local CoolDownTime = 12
local isCoolDown = false
local function CoolDown()
isCoolDown = true
while task.wait(1) do
if CoolDownTime >= 2 and isCoolDown == true then
--code
CoolDownTime -= 1
elseif CoolDownTime <= 1 then
--code
end
end
end
every time you rob it the cooldown function gets called
You need to end the loop when the countdown is over. Take the task.wait out of the while loop declaration and replace it with a condition to end the loop when the countdown is over
Yup like he said, the variable called isCoolDown is used only to check the loop is running which makes it redundant. This is probably all you need, check isCoolDown == false to allow people to rob, i.e…
local function CoolDown()
isCoolDown = true;
wait(CoolDownTime);
isCoolDown = false;
end
Just so you’re aware, this code is going to lead to a memory leak, a new ‘while true do’ loop is began each time the ‘CoolDown’ function is called, remember to explicitly break out of loops via a ‘break’ statement or use a condition which can be false (task.wait(1) will always be considered truthy).
Yeah quite right, but I did say though in my answer. You only call this function when isCoolDown == false so you will not get any overlaps in CoolDown() being called. Provided the logic that leads to this function being called (i.e. a Remote or whatever that checks isCoolDown==false which then executes the CoolDown function) there should be no multiple instances of the function being called. The while true do loop is gone and there is no need for it when all you are doing is waiting for a countdown to expire. If there was some Gui Text displaying the countdown then you would need the while true do to adjust the text every second, but since it is simply a countdown there is nothing to do but wait until it finishes.