✓ Accepted answer
I think there's some slight issues with your logic.
Firstly, your **db **and **Cooldown ** variables should not be inside of your function. The way you have it right now, whenever you click the TextButton, no matter what, db will always be false.
Next, I've deleted your if statement that detects when the text will be equal to "Cooldown:0". We know that by the time the forloop finishes, that it would be equal to that, so what you did was redundant and somewhat pointless(although it would work). Instead, I simply changed the text to spawn once the loop was done running (after 10 seconds).
Not quite sure what you were trying to do with the wait(Cooldown), but your loop ran ten times, for 1 second each, which equals 10 seconds. As such, I removed that part.
The working code should look like this:
local Cooldown = 10
local db = false
script.Parent.MouseButton1Click:Connect(function(plr)
if db == false then
db = true
for i = Cooldown, 0, -1 do
wait(1)
script.Parent.Text = "Cooldown: "..i
end
script.Parent.Text = "Spawn"
db = false
end
end)
1 comment
local db = false should be outside the event