Reset two different cooldowns when one button clicked

Hello. I have two UI buttons, one with a cooldown of 5 seconds and one with a cooldown of 10. Let’s say if the button with 5 seconds is clicked, both buttons will return to their cooldowns.

I can’t seem to do it. Any help would be appreciated.
(PS. I don’t have much scripting experience, if any of my scripts look bad, that’s why.)

You can try a os.clock() or an equivalent to “tick” the time it last time pressed a button. Check with new ticks with the old tick to see if the difference is larger than 5 or 10 each.

Try this:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local EmergencyBackup = script.Parent.EmergencyBackup
local Infantry = script.Parent.Infantry
local Rocketeer = script.Parent.Rocketeer

local ebdb, idb, rdb = false, false, false

local InfantryStack
local RocketeerStack

local function ResetCooldowns()
    if InfantryStack then task.cancel(InfantryStack) end
    if RocketeerStack then task.cancel(RocketeerStack) end

    InfantryStack = task.spawn(function()
        idb = true
        for i = 5, 0, -1 do
            Infantry.Text = i
            task.wait(1)
        end
        idb = false
        Infantry.Text = "Infantry"
        InfantryStack = nil
    end)

    RocketeerStack = task.spawn(function()
        rdb = true
        for i = 10, 0, -1 do
            Rocketeer.Text = i
            task.wait(1)
        end
        rdb = false
        Rockeeter.Text = "Rocketeer"
        RocketeerStack = nil
    end)
end

EmergencyBackup.MouseButton1Click:Connect(function()
    if ebdb then return end
    ebdb = true
    ReplicatedStorage.Spawn:FireServer(5, "Blue", "Infantry")
    for i = 60, 0, -1 do
        EmergencyBackup.Text = i
        task.wait(1)
    end
    EmergencyBackup.Text = "Emergency Backup"
    ebdb = false
end)

Infantry.MouseButton1Click:Connect(function()
    if idb then return end
    ResetCooldowns()
    ReplicatedStorage.Spawn:FireServer(5, "Blue", "Infantry")
end)

Rocketeer.MouseButton1Click:Connect(function()
    if rdb then return end
    ResetCooldowns()
    ReplicatedStorage.Spawn:FireServer(5, "Blue", "Rocketeer")
end)