I was making a single player and i want it so that if the player clicked the button, they didn't die. But if the player didn't click the button after 8 seconds, they die.
The only problem is that the button is not working even if i think it was correct. I'm new to scripting. The code was in a normal script with the button as it's parent. Thanks for reading!
Code :
correctVar = false
wait(10) script.Parent.Visible = true wait(8) if correctVar == false then script.Parent.Parent.Parent.Parent..Character.Humanoid.Health = 0 script.Parent.Visible = false end
script.Parent.MouseButton1Down:Connect(function() correctVar = true script.Parent.Visible = false print("The player clicked the button!") end)
The player can't click the button, but they die after 8 seconds.
It's because when you do the click function, you don't link it to the click detector. The type of click function you used is for GUIs. Instead of
script.Parent.MouseButton1Down:Connect(function()
You should do
script.Parent.ClickDetector.MouseClick:Connect(function()