How to check since when a value is true?

So i want to make a sort of ability button and when you activated the button it will have a 30 seconds cooldown which also displaying the timer and when it run out you can use it again.
Is there a way i could make this?

You could save when the ability was used using tick() (gives back the time in miliseconds) and then check if it was 30 seconds ago like this:

local lastUsed = tick() -- do this when they use the ability

if lastUsed + 30 <= tick() then -- this checks if the lastUsed was 30 seconds ago
end 

One simple way would be to add a debounce variable, and check if the denounce ended everytime the Player attempts to active the button.

local denounce = false
local button = script.Parent

button.Triggered:Connect(function(Player) -- We’re assuming the script is parented under a ProximityPrompt, feel free to change the Triggered.
   if denounce == false then
     denounce = true
     -- other code here
end)

Includes timer:

local bob = false
Button.MouseButton1Down:Connect(function()
    if bob = false then
         bob  = true
         for i = 30, 0, -1 do
			Button.TextLabel.Text = i.."s"
			wait(1)
			if i == 0 then
				bob = false
                Button.TextLabel.Text = "Clickable!"
			end
		end
    end
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.