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.
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)