在Roblox脚本中出现“Workspace.RedPedastal.Script:17: attempt to index function with 'Transparency'”错误

我正在制作一个Roblox脚本,用于传送玩家并制作“光束”动画,但是当我通过踩在传送区域上激活脚本时,会出现以下错误:

Workspace.RedPedastal.Script:17: attempt to index function with 'Transparency'

代码:

local Teleport = "BeachHill"
local Beam = workspace.Beam

function Beam() #仅作备用
    for i = 0, 100, 1 do
        Beam.Transparency = 1 - i/100
        Beam.Size = Vector3.new(2048, 1.8 + i/10, 1.8 + i/10)
        print(Beam.Transparency, Beam.Size)
    end
end

function Touch (hit)
    if script.Parent.Locked == false and script.Parent.Parent : FindFirstChild(Teleport).Locked == false then script.Parent.Locked = true script.Parent.Parent:FindFirstChild(Teleport).Locked=true
        local Pos = script.Parent.Parent:FindFirstChild(Teleport)
        hit.parent:moveTo(Pos.Position)
        for i = 0, 100, 1 do
            Beam.Transparency = Beam.Transparency - 0.01 #<- 错误
            Beam.Size = Vector3.new(2048, 1.8 + i/10, 1.8 + i/10)
            print(Beam.Transparency, Beam.Size)
        end
        wait(1)
        script.Parent.Locked = false
        script.Parent.Parent:FindFirstChild(Teleport).Locked = false
        end
           end
    script.Parent.Touched:connect(Touch)

原文链接 https://stackoverflow.com/questions/70536491

点赞
stackoverflow用户7509065
stackoverflow用户7509065

在 Lua 中,函数和变量存在于同一命名空间中,因此您不能在同一位置同时使用名为 Beam 的函数和变量。

2021-12-30 21:01:39