Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to add a visual cooldown on a button?

Asked by
nicros 165
8 years ago

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

Log in to vote
1
Answered by 8 years ago

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

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, nicros 165 — 8y
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. Ryzox 220 — 8y
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 nicros 165 — 8y
Ad

Answer this question