RunService or task.delay for timing hundreds of objects?

Hi,

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
1 Like

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).

1 Like

Or use collection service so you don’t have to spawn a bunch of threads, I think that’s an option

1 Like

Thats what this is supposed to be, and CollectionService isnt something that solves that issue, its used to keep things organized.

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)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.