Thanks for the reply , but what if you had a local script for a gun, and you needed to wait and halt the gun from shooting because your reloading? Like this:
cooldown = 2
fire()
wait(cooldown)
fire()
How would you use RunService to wait 2 seconds instead of using wait() function?
Like this. Using RunService will get you waits accurate down to a single frame (1/60), which is usually way more than enough for most use cases. Here, it defaults to a frame if you don’t pass in an argument.
local rs = game:GetService(“RunService”)
local wait = function(t)
t = t or rs.Heartbeat:Wait()
local now = tick()
repeat rs.Heartbeat:Wait() until tick() - now >= t
end
There are so many ways to do something like this, this is just one method of doing it
This doesn’t do anything to performance. It does exactly what a wait() is supposed to do. It just yields the script. Just that with this, it’s more accurate, reliable, and you have precision down to a single frame (1/60 seconds), compared to wait()’s 1/30 second minimum.