Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is this GUI script that interacts with items in Workspace not working?

Asked by 8 years ago

The script is supposed to detect items in Workspace and change accordingly to them. However, the script does not work at all, and I have no idea why, as output didn't give me anything.

Can someone please help me? Here's the script:

local GameOn = game.ServerScriptService.MainGame:WaitForChild("Playing")

while wait(0.1) do
    if GameOn.Value == true then
        if game.Workspace:WaitForChild("Bomb") then
            if game.Workspace.Bomb:WaitForChild("Armed Bomb") then
                if game.Workspace.Bomb["Armed Bomb"].Armed.Value == true then
                    script.Parent.Visible = true
                    script.Parent.Start.Value = true
                    script.Parent.Timer.Value = 60
                end
            elseif game.Workspace.Bomb:WaitForChild("Defused Bomb") then
                script.Parent.Visible = false
                script.Parent.Start.Value = false
                script.Parent.Timer.Value = 0
            end
        end
    end
end
0
Inside the while loop, use FindFirstChild instead of WaitForChild MechaScripter 35 — 8y
0
Thanks! That fixed it! CoolJohnnyboy 121 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago
local GameOn = game.ServerScriptService.MainGame:WaitForChild("Playing")

while wait(0.1) do
    if GameOn.Value == true then
        if game.Workspace:WaitForChild("Bomb") then
            if game.Workspace.Bomb:FindFirstChild("Armed Bomb") then
                if game.Workspace.Bomb["Armed Bomb"].Armed.Value == true then
                    script.Parent.Visible = true
                    script.Parent.Start.Value = true
                    script.Parent.Timer.Value = 60
                end
            elseif game.Workspace.Bomb:FindFirstChild("Defused Bomb") then
                script.Parent.Visible = false
                script.Parent.Start.Value = false
                script.Parent.Timer.Value = 0
            end
        end
    end
end

Now let me tell you what's wrong with this script. You used WaitForChild. WaitForChild is a yield, or something that waits for something. So this won't work. But this can be easily replaced by FindFirstChild. FindFirstChild won't return nil if it finds something, so in true/false statement terms. It will return true if something is found.

Written with StackEdit. by hungryjaffer

Ad

Answer this question