An alternative to wait, but keeping the cooldown

So I’m searching for an alternative to wait(), but keeping the time to wait, something like.

print("Hi")

RunService.Heartbeat:Wait(10)

print("Bye")

The idea is to print “Hi” (Action1) and after 10 seconds “Bye” (Action2), but without using wait(). Im not really sure if there is a way to do that.

3 Likes

Here’s a quick and easy alternative wait() function.

https://gist.github.com/CloneTrooper1019/4ae7113f6ccfa666caa0c3991398e21a

Slap it in a module, then do something like this;

local FastWait = require(ModuleScript) --require wherever your put the module

print("hi")
FastWait(10)
print("bye)
2 Likes

You can use tick()
Yes, I know people say it’s deprecated.

So, tick() gets the amount of seconds passed since January 1st 1970. Lol I know right! Why did Roblox even make this you may ask? Tick can be helpful if you’re creating some kind of a system that requires a timestamp of some sort, such as debouncing or cooldowns or whatever. So let me show you what we can do with tick().

local start = tick() --UNIX Epoch time in seconds
print("Hi")

while true do
    wait()
    if tick() - start >= 5 then
        print("Bye")
        break
    end
end

Of course it would look better as a debounce and not usage for a while loop if you get what I mean?

Let me demonstate an example

local start = tick()
--Let's say tick() is equal to 20 in this case
--Every second it incements by 1 (if you think in seconds)

part.Touched:Connect(function()
    if tick() - start >= 3 then
        start = tick()
        print("Part Touched and successfully ran debounce")
    end
end)
2 Likes