Title is vague so i’ll go more into detail. I’m trying to replicate a Cooldown System shown here: https://gyazo.com/2e24e748afa9eeaff1e4ce12ad0edaed
I just need help with making a script that’ll edit the text of a Text Button, making it count down from a certain number (with decimals). All help appreciated!
1 Like
local button = -- reference button
local cooldown = 5
local debounce = true
button.MouseButton1Click:Connect(function()
if debounce then
debounce = false
-- Do the thing you want here
for i = 5, 1, -0.1 do
button.Text = i
end
debounce = true
end
end)
It will look something like the above. Modify it to meet your needs.
1 Like
You could do something like this:
local screen = script.Parent
local ability_button = screen:WaitForChild("AbilityButton")
local ABILITY_COOLDOWN_TIME = 1.5
ability_button.MouseButton1Click:Connect(function()
if ability_button.CooldownLabel.Visible then return end
coroutine.wrap(function()
ability_button.NameLabel.Visible = false
ability_button.CooldownLabel.Visible = true
local time_left = ABILITY_COOLDOWN_TIME
while time_left > 0 do
ability_button.CooldownLabel.Text = ("%.1f"):format(time_left)
local dt = wait()
time_left -= dt
end
ability_button.NameLabel.Visible = true
ability_button.CooldownLabel.Visible = false
end)()
end)
You can change the string format to change what the number looks like. If you want two decimals, change “%.1f” to “%.2f”.
2 Likes