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

Button isn't working once clicked. Suppose to stop all sounds. Why?

workspace.CodeRedButton.ClickDetector.MouseClick:Connect(function()
	script.Parent.ClickDetector:Destroy()
	script.Parent.SurfaceGui.TextLabel.Text = "Please Wait"
	wait(5)
	Instance.new("ClickDetector", script.Parent)
	script.Parent.SurfaceGui.TextLabel.Text = "Disable Code Red"
end)

script.Parent.ClickDetector.MouseClick:Connect(function()
	for i,v in pairs(workspace.Lights.Lights:GetChildren()) do
		if v:IsA("Part") then
			v.BrickColor = BrickColor.new("White")
		end
	end
	workspace.Breach:Stop()
	wait(3)
end)

2nd function doesn't work. No error codes.

6 comments

0

What's not working correctly? Are you trying to find and stop playing all the sounds inside the part?

0

Is this in a local script?

0

Have you tried replacing .Sound3 with ["Sound3"] or :FindFirstChild("Sound3")?

0

This is a server script.

0

I made edits to the script.

0

Don't use :Stop()

1 answer

It is not a good practice to destory the clickDetector, as when you create the new one you would need to reassign the events. Instead use a property on the clickDetector called "MaxActivationDistance" and set it to zero to disable the button.

workspace.CodeRedButton.ClickDetector.MouseClick:Connect(function()
    script.Parent.ClickDetector.MaxActivationDistance = 0
    script.Parent.SurfaceGui.TextLabel.Text = "Please Wait"
    wait(5)
    script.Parent.ClickDetector.MaxActivationDistance= 32
    script.Parent.SurfaceGui.TextLabel.Text = "Disable Code Red"
end)

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