i wanna add cooldown but it doesn’t work ! i am making a rng game coz i finished my other game and the cooldown doesn’t work as u can see i made “wait(5)” in the end
script:
local btn = script.Parent
local txt = btn.Parent.Background:WaitForChild("TextLabel")
local CC = workspace.CoinCollection
local x = game.Players.LocalPlayer:WaitForChild("leaderstats")
local tokens = x:WaitForChild("Tokens")
btn.MouseButton1Click:Connect(function()
txt.Parent.Visible = true
local rng = Random.new()
local num = rng:NextInteger(1, 100)
txt.Text = tostring(num)
tokens.Value = tokens.Value + num
CC:Play()
end)
wait(5)
That’s because you’re not placing this cooldown in the actual MouseButton1Click event, so the script just wait for 5 seconds once, Try placing this cooldown into the MouseButton1Click event like this:
local btn = script.Parent
local txt = btn.Parent.Background:WaitForChild("TextLabel")
local CC = workspace.CoinCollection
local x = game.Players.LocalPlayer:WaitForChild("leaderstats")
local tokens = x:WaitForChild("Tokens")
local debounce = false
btn.MouseButton1Click:Connect(function()
if not debounce then
debounce = true
txt.Parent.Visible = true
local rng = Random.new()
local num = rng:NextInteger(1, 100)
txt.Text = tostring(num)
tokens.Value = tokens.Value + num
CC:Play()
wait(5)
debounce = true
end
end)