Task.wait() for stepped

Yeah, I guess so. All my tutorial videos used wait() so I learned bad habits.

well no one is perfect, you will always learn new things

Is it equivalent to RunService.Heartbeat:Wait()?

edit: Also, what if I check physics and affect physics in on script, should I use heartbeat or stepped?

No. task.wait() is equivalent to wait(). That’s what me and @D0RYU just said.

not exactly, I recommend looking at these two links to get a better understanding of the differences

https://developer.roblox.com/en-us/api-reference/class/RunService

technically task.wait() messes with frames, but these are not the same thing

I did look at them, and it says.

1 Like

yes, but they don’t do the exact same thing
task.wait() wouldn’t exist if they did the same thing

As far as I know there is currently no actual replacement for a Stepped wait. You’d have to write your own. Here’s an example on how to do that

local function steppedWait(t)
    local start = os.clock()
    while os.clock() - start < t do
        game:GetService("RunService").Stepped:Wait()
    end
    return os.clock() - start
end

I know that they return different delta time, what other differences are there?

task.wait() is a lot easier to write, that’s one thing for sure lol.

1 Like

well for starters
task.wait() has a time parameter
Heartbeat can be made into a connection so :Wait() works

you use them for different things

you couldn’t do Heartbeat:Wait(5) like you can with task.wait(5)

1 Like

Heartbeat runs after Stepped
Stepped runs after RenderStepped
and RenderStepped runs first

image

1 Like

task.wait() is a simple, more efficient way to do wait() mainly.

This is different though.

Heartbeat:Connect() is different too

What I’m saying is, is task.wait() the same as Heartbeat:Wait()?

Without any parameters and excluding the different delta times.

if you don’t add any time argument into task.wait() then they are the same

EDIT: should have said this sooner, my bad

So, I connect heartbeat if I check physics, and connect stepped if I affect physics?

What if I check and affect physics in one function, what do I connect?

well Stepped runs before physics happen, so if you need to mess with the physics I recommend using Heartbeat

1 Like

API Reference says otherwise.
image

you should read the api better
this applies with the :Connect() parameters, not :Wait()

try this code and tell me if it waits 30 seconds, because it doesn’t

local RunService = game:GetService("RunService")

RunService.Heartbeat:Wait(10)
RunService.Stepped:Wait(10)
RunService.RenderStepped:Wait(10)

print("test")

Thought you said stepped because of the title of the topic, apologies.

1 Like