I want to know two things: Is this the best way to do this, and how can I make it not in event form, meaning is there a way to make it not create a new thread every time?
local Interval = 1
local NextCheck = 0
RunService.Heartbeat:Connect(function()
local CurrentTime = os.time()
if CurrentTime < NextCheck then
return
end
NextCheck = CurrentTime + Interval
end)
You can use RunService.Heartbeat:Wait() in a loop. I’d also recommend using tick() instead of os.time(), but the difference might be negligible. I think tick() is more commonly used for this kind of thing - not entirely sure why, but there’s probably a reason.
However I will say that the difference between the event and using :Wait() will be pretty minimal too.
local Interval = 1
local NextCheck = 0
while true do
RunService.Heartbeat:Wait()
local CurrentTime = tick()
if CurrentTime < NextCheck then
return
end
NextCheck = CurrentTime + Interval
end