So I’m trying to have a specific group of objects have a timer of when something one them will occur. However while testing different ways of doing it, I noticed that I can use RunSerivce and task.delay for the same usage, but which is more efficient to use when it comes to hundreds of objects?
-- using task.delay()
function execute(object)
-- stuff
task.delay(time, execute, object) -- Recursion
end
task.delay(time, execute, delay)
-- using RunService
RunService.Heartbeat:Connect(function()
for i,v in Group do
-- very quick mathz for time
if sometime >= time then
-- stuff
end
end
end
task.delay will be more efficient since it’ll schedule the task via Roblox’s task scheduler. Heartbeat on the other hand will execute that function every frame (including frames where the function isn’t doing anything).
I did some testing with the MicroProfiler, and some benchmark testing, and it does appears to work better than firing 60 frames a second (who would’ve guessed)