Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

2 comments

0

Inside the while loop, use FindFirstChild instead of WaitForChild

0

Thanks! That fixed it!

1 answer

✓ Accepted answer
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

This discussion is preserved as it was. New answers, comments, and votes are closed.