禁用激光而不是启用? (ROBLOX Lua)

Disable lasers instead of being enabled? (ROBLOX Lua)

嘿 Whosebug 社区。所以我开始在 ROBLOX 中研究 "Tycoon"。我已经收集了几个自定义模型,但我 运行 遇到了其中一个的问题。基本上,我希望每个玩家基地都有一个激光门。我遇到的问题是激光门的激光在游戏开始时启用。就个人而言,我希望它们在开始时被禁用,以便玩家稍后可以手动启用它们。我之所以纠结于此是因为我不是编写脚本的人,但是我尝试解决它但没有成功。

script.LazerGateLocalScript.LazerGate.Value = script.Parent -- setting a 
value
local configs = script.Parent.Configurations
local lazers = script.Parent.LazerGate -- making it easier to access this 
part
local lazersOn = true -- so we know if the lasers are on or off

for i, node in pairs(lazers:GetChildren()) do
for i, component in pairs(node:GetChildren()) do
    if component.Name == "Emitter" then
        local lazerBeam = component:FindFirstChild("ParticleEmitter")
        local lazerColor = configs.LazerColor.Value
        lazerBeam.Color = ColorSequence.new(lazerColor, lazerColor) -- Setting the lazer color to the lazer color found in the configurations of this model
    elseif component.Name == "Diode" then
        component.BrickColor = configs.DiodeColor.Value
        local diodeSparkle = component:FindFirstChild("ParticleEmitter")
        diodeSparkle.Color = ColorSequence.new(Color3.new(255,255,255), configs.DiodeSparkleColor.Value)
    elseif component.Name == "Lense" then
        component.BrickColor = configs.DiodeColor.Value
    end
end
end

script.Parent.KillBrick.PointLight.Color = configs.LazerColor.Value

game.Players.PlayerAdded:connect(function(player) -- when a player is added
player.CharacterAdded:connect(function() -- and whenever their character is loaded then
    local newScript = script.LazerGateLocalScript:Clone() -- clone the local script
    newScript.Parent = player.PlayerGui -- and put it in the player's playerGui
end)
end)




function lazerToggle(OnOff) -- this funtionc simply changes whether the lasers are on or off
for i, node in pairs(lazers:GetChildren()) do
    for i, component in pairs(node:GetChildren()) do
        if component.Name == "Emitter" then
            local lazerBeam = component:FindFirstChild("ParticleEmitter")
            if OnOff == true then
                lazerBeam.Enabled = true
            else
                lazerBeam.Enabled = false
            end
        end
    end
end
end

script.Parent.KillBrick.Touched:connect(function(obj)
if obj.Parent and obj.Parent:FindFirstChild("Humanoid") and lazersOn == true then
    obj.Parent:BreakJoints()
end
end)

script.Parent.LazerToggle.OnServerEvent:connect(function() -- when an event is fired  then see if we are to open or close the lid and set a value to do so
if lazersOn == true then
    lazerToggle(false)
    wait(1.5)
    lazersOn = false
else
    lazerToggle(true)
    wait(0.5)
    lazersOn = true
end
end)

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

mouse.Button1Down:connect(function() -- if the player chicks then ...
if script.LazerGate.Value and mouse.Target.Name == "LazerButton" and mouse.Target.Parent.Name == "LazerGateSection" then -- if they click the laser gates button
    script.LazerGate.Value.LazerToggle:FireServer() -- fire an event that the script will use
end
end)

再一次,我的问题是我希望禁用激光,而不是一开始就启用。任何帮助将不胜感激。此外,我非常清楚我将收到对此 post (xD) 的反对票。但我真的很感激任何帮助!

提前致谢, E.W

根据代码告诉我的,这应该有效:

    script.LazerGateLocalScript.LazerGate.Value = script.Parent
    local configs = script.Parent.Configurations
    local lazers = script.Parent.LazerGate
    local lazersOn = false

    for _, node in pairs(lazers:GetChildren()) do
        for _, component in pairs(node:GetChildren()) do
            if component.Name == "Emitter" then
                local lazerBeam = component:FindFirstChild("ParticleEmitter")
                local lazerColor = configs.LazerColor.Value
                lazerBeam.Color = ColorSequence.new(lazerColor, lazerColor)
            elseif component.Name == "Diode" then
                component.BrickColor = configs.DiodeColor.Value
                local diodeSparkle = component:FindFirstChild("ParticleEmitter")
                diodeSparkle.Color = ColorSequence.new(Color3.new(255,255,255), configs.DiodeSparkleColor.Value)
            elseif component.Name == "Lense" then
                component.BrickColor = configs.DiodeColor.Value
            end
        end
    end

    script.Parent.KillBrick.PointLight.Color = configs.LazerColor.Value
    game.Players.PlayerAdded:connect(function(player)
        player.CharacterAdded:connect(function()
            local newScript = script.LazerGateLocalScript:Clone()
            newScript.Parent = player.PlayerGui
        end)
    end)

    function lazerToggle(OnOff)
        for _, node in pairs(lazers:GetChildren()) do
            for _, component in pairs(node:GetChildren()) do
                if component.Name == "Emitter" then
                    local lazerBeam = component:FindFirstChild("ParticleEmitter")
                    if OnOff then
                        lazerBeam.Enabled = true
                    else
                        lazerBeam.Enabled = false
                    end
                end
            end
        end
    end

    script.Parent.KillBrick.Touched:connect(function(obj)
        if obj.Parent and obj.Parent:FindFirstChild("Humanoid") and lazersOn == true then
            obj.Parent:BreakJoints()
        end
    end)

    script.Parent.LazerToggle.OnServerEvent:connect(function()
        if lazersOn == true then
            lazerToggle(false)
            wait(1.5)
            lazersOn = false
        else
            lazerToggle(true)
            wait(0.5)
            lazersOn = true
        end
    end)
    lazerToggle(false);

上面的代码进入第一个脚本,服务器端脚本有一个名为 LazerGateLocalScript 的子脚本。

    local player = game.Players.LocalPlayer
    local mouse = player:GetMouse()
    mouse.Button1Down:connect(function()
        if script.LazerGate.Value and mouse.Target.Name == "LazerButton" and mouse.Target.Parent.Name == "LazerGateSection" then
            script.LazerGate.Value.LazerToggle:FireServer()
        end
    end)

然后上面的代码进入本地脚本,它是名为 LazerGateLocalScript 的服务器脚本的子脚本

只要你问,是的,我知道 RobloxLua。