[help] FiveM Job Cooldown

I have this code right here:

Citizen.CreateThread(function()
    while true do
        Wait(0)
        local jucator = PlayerPedId(-1)
        local coordjuc = GetEntityCoords(jucator)
        for k,v in pairs(animatiecoord) do
            local Distanta = GetDistanceBetweenCoords(coordjuc.x, coordjuc.y, coordjuc.z, v[1], v[2], v[3], true)
                if Distanta < 0.5 then
                    if IsControlJustPressed(1, 38) then
                        TaskStartScenarioInPlace(PlayerPedId(), "WORLD_HUMAN_BUM_WASH", 0, true)
                        Wait(10000)
                        TriggerServerEvent("DICLO:SPALAGEAMURI")
                        ClearPedTasks(PlayerPedId())
                end
            end
        end
    end
    Citizen.Await(10000)
end)

I want a cooldown after the animation is done, but i don’t know how to put it in the code ! Any help?
I tried it with the Citizen.Await at the end, how a friend told me to do, but it doesn’t work.

The Citizen.Await(10000) will never be executed because you haven’t got a break instruction to stop the infinite loop…

How do I do that, I can’t figure it out

Maybe something like this?

Thank you very much ! This is perfect

1 more question… how can i send i massage like " You have to wait X more seconds until you can do it again" ?

cooldownGeamuriTime = 10        -- time for cooldown in seconds

cooldownGeamuri = false     -- don't modify
Citizen.CreateThread(function()
    while true do
        Wait(0)
        local jucator = PlayerPedId()
        local coordjuc = GetEntityCoords(jucator)
        for k,v in pairs(animatiecoord) do
            local Distanta = GetDistanceBetweenCoords(coordjuc.x, coordjuc.y, coordjuc.z, v[1], v[2], v[3], true)
            if Distanta < 0.5 then
                if IsControlJustPressed(1, 38) and cooldownGeamuri == false then
                    TaskStartScenarioInPlace(PlayerPedId(), "WORLD_HUMAN_BUM_WASH", 0, true)
                    Wait(10000)
                    TriggerServerEvent("DICLO:SPALAGEAMURI")
                    ClearPedTasks(PlayerPedId())
                    TriggerEvent('cooldown:geamuri')
                elseif IsControlJustPressed(1, 38) and cooldownGeamuri == true then
                    TriggerEvent('chatMessage', '', {255, 255, 255}, "Trebuie sa mai astepti "..timeRemaining.." secunde.")
                end
            end
        end
    end
end)

RegisterNetEvent('cooldown:geamuri')
AddEventHandler('cooldown:geamuri', function()
    cooldownGeamuri = true
    timeRemaining = cooldownGeamuriTime
    local temp = cooldownGeamuriTime
    for i = 1, temp do
        Citizen.Wait(1000)
        timeRemaining = timeRemaining - 1
    end
    cooldownGeamuri = false
end)

Try this, should work.

Hi, will this work if i want to use this code to make a cooldown for lets say 45minutes? And what happen if the person relogs?

Hi, this code I made is useful when the cooldown is short, in this case it is 10 seconds long, so re-logging would make no sense since it’s such a short period of time to wait. I also don’t recommend making a script wait for 45 minutes using the Citizen.Wait(). Also, in the code I provided there’s no checking for re-logging as you asked, so the player would be able to reconnect to bypass the cooldown. I would think of using the os.time() functions server side for such a long cooldown.