Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to add a visual cooldown on a button?

so ive got a teleport book in my game and i want to add a visual cooldown along with an actual one.

heres the script ive got

local reqLevel = 1
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Down:connect(function()
    if player.leaderstats.Lvl.Value >= reqLevel and player.Character then
        player.Character:MoveTo(Vector3.new(173.51, 385.797, 118.025))
		
    end
end)

i could just add

script.Parent.Visible = false
wait(120)
script.Parent.Visible = true

after the coords but im needing a visual timer and im lost with that, im assuming it would be done with a for loop, but i dont know how to make it a visual count down on the book, any help to steer me in the right direction would be appreciated :P

1 answer

✓ Accepted answer

for the visual countdown I would recommend a While Wait() do loop, so just edit as follows

a = 0 -- Used to set a's first value
Place_number_amount_here = 10 --Type amount of times you want loop to run here!
--Two values not needed, just used to make it easier.
num = Place_number_amount_here
while wait() do
	a = a - 1 --subtracts 1 to a
	--Code goes here
	if a == num then --Get number
		break -- Stop loop if a == num.
	end
end

Hope this helped

3 comments

0

Thanks for the reply. so i put this into my script like you said, but do i have to do something with a textlabel? because i dont see how it would print out the timer on my book :p sorry when i said noob i meant big time noob,

0

This will not work you will need to place it in a coroutine and a for loop would be much more helpful. It would work on it's own but if you're adding to your game you need coroutines.

0

thanks for the help both of you, i ended up mixing my buttons and script with a stop watch script i had and inverted that script to count down instead of up

This discussion is preserved as it was. New answers, comments, and votes are closed.