为什么当这个脚本的组件时,它们 运行 很好但拼凑起来却不起作用?这可能只是一个问题

Why when the components of this script, do they run fine but do not work when pieced together? There may just be a problem with it all together

此脚本来自 Roblox Studio,位于 Lua。我曾尝试使用单独的脚本,但是当我这样做时,由于 bool 值,它们不起作用。脚本似乎要么不响应它,要么它只是没有正确更新。 I have attached the picture of the hierarchy from ROBLOX Studio。我是 Lua 的新手,但我熟悉基本概念。我也很了解 Roblox Studio 界面。如果有人可以提供帮助,将不胜感激。提前致谢。

local lockvalue = script.Parent.Lockdown.Value
lockvalue = false
local RobBank = script.Parent["Rob Bank"]
local ClickDetector = RobBank:WaitForChild("ClickDetector")
local BillboardCXZ = RobBank:WaitForChild("BillboardGui")
local Billboard = BillboardCXZ:WaitForChild("TextLabel")
local emergencylight1 = script.Parent.Parent.EmergencyLight.Toggle.Value
local emergencylight2 = script.Parent.Parent.EmergencyLight2.Toggle.Value
local emergencylight3 = script.Parent.Parent.EmergencyLight3.Toggle.Value
local alarm1 = script.Parent.Parent.Alarm1.AlarmSound
local alarm2 = script.Parent.ParentAlarm2.AlarmSound
local Notif1 = script.Parent.NotifcationScreen.SurfaceGui.Frame.Visible
local Notif2 = script.Parent.NotifcationScreen.SurfaceGui.Frame.TextButton.MouseButton1Click
print ("Values Loaded.")



local function lock()
    print ("LOCK FUNCTION ACTIVATED")
    emergencylight1 = true
    emergencylight2 = true
    emergencylight3 = true
    alarm1:play()
    alarm2:play()
    lockvalue = true
    Notif1 = true
end

local function unlock()
    print ("UNLOCK FUNCTION ACTIVATED")
    emergencylight1 = false
    emergencylight2 = false
    emergencylight3 = false
    alarm1.stop()
    alarm2:stop()
    lockvalue = false
    Notif1 = false
end


Notif2:Connect(function()

unlock()
print ("Unlocked Via Override")

end)




RobBank.ClickDetector.MouseClick:Connect(function(Player)
print ("Functioning")
if Player and Player.Character then
print ("Milestone 2")
        if lockvalue == false then
    print ("After Lock Value")
          if Player.Team == game.Teams.Criminal then
            print ("Team Check")        
            local clicks = Player:FindFirstChild("leaderstats")["Bounty"]
            clicks.Value = clicks.Value + 500
            local clicks2 = Player:FindFirstChild("leaderstats")["Cash"]
            clicks2.Value = clicks2.Value + 2500
            Billboard.TextColor3 = Color3.new(1,0,0)
            lock()
            wait(60)
            unlock()
            Billboard.TextColor3 = Color3.new(0,1,0)
          else
                print("Player Is not On Crim team.")
                Billboard.Text = ("You are on the Wrong Team!")
                wait(3)
                Billboard.Text = ("Steal Cash")
          end

        else
            Billboard.Text = ("Already been recently robbed!")
            wait(3)
            Billboard.Text = ("Steal Cash")
        end
    end
end)

在Lua中,变量可以是对table的引用,其中有children(key/value对):

local myTable = { }
myTable.myKey = true

但是,如果您引用单个 child(通过其键),那么它将计算结果值并将其仅传递给变量(而不是对键本身的引用).

local newVar = myTable.myKey
print(newVar)         -- true
newVar = false
print(newVar)         -- false
print(myTable.myKey)  -- true, because we never changed myKey

所以在下面的语句中,emergencylight1 可能是值 'true' 或 'false' 而不是对 属性 本身的引用。

local emergencylight1 = script.Parent.Parent.EmergencyLight.Toggle.Value

推荐

确保您的变量是对实际 table 的引用,然后在分配新值时引用 table 的 child(通过其键)。

local emergencylighttoggle1 = script.Parent.Parent.EmergencyLight.Toggle
local emergencylighttoggle2 = script.Parent.Parent.EmergencyLight2.Toggle
local emergencylighttoggle3 = script.Parent.Parent.EmergencyLight3.Toggle

local function lock()
    emergencylighttoggle1.Value = true
    emergencylighttoggle2.Value = true
    emergencylighttoggle3.Value = true
end


local function unlock()
    emergencylighttoggle1.Value = false
    emergencylighttoggle2.Value = false
    emergencylighttoggle3.Value = false
end