I have a gui button that when you click on it it respawns the player. The problem is, if you spam the button it crashes the game. I've tried to make a bool value to solve this but you can still spam it. Any solutions?
local player = game.Players.LocalPlayer
local cooldown = script.Parent.Value
cooldown = false
if cooldown == false then
function OnClicked()
player:LoadCharacter()
cooldown = true
wait(5)
end
end
cooldown = false
script.Parent.MouseButton1Down:connect(OnClicked)print("player respawned")

1 comment
Is your code inside of a big loop?