Wait but without stopping the script

so i want to make a 2 seconds timer since the player made an action but i need to find a way to make it in the script and when the player repeats this action timer should go back to 0 and also it can’t be wait cause the script will freeze until it will stop waiting and that is bad pls help.!

i tried to make something with connections it was smth like:

//i made an event so that kind of bad but idk how to make a connection without it //

locl connection = nil
if connection ~= nil then
connection:Disconnect()
end
Event.Event:Connect(function()
wait(2)
do thing
end)
Event:Fire()

and it wasnt working cuz the connectiong wasnt disconnecting for some reason and i have no idea how to solve this problem it shouldnt be that hard right?

i hope you can understand this language

You can use task.delay(seconds, function) to run a piece of code after a certain delay (without pausing the entire script)

Example:

task.delay(2, function()
    -- Do thing
end)
4 Likes

thanks but these things are stucking up so if the player does the same auction timer won’t go back to 0 and that --DO THING will happend earlier than it should

1 Like

local check = 0
check = check + 1
task.delay(2, function()
if check == 1 then
–thing does the thing
end
check = check-1
end)

so that works i am not sure how but my brain works only 10% of the time so yeah thanks i will approve ur post it helped

1 Like