What is RunService and why should I use it?

Hello All! Today I have a question about what is runservice? I have seen a few scripts that have it and I would like to ask the community why do people use it and when should I use it? And if someone could explain a good bit about what it… is?

Thank you!

5 Likes

RunService

It’s a service ROBLOX provides that gives some neat time-management methods and events like Stepped, Heartbeat, and IsStudio(). It’s used whenever

  • you need to know what context the game is running in (studio, run, play, etc.)
  • you need your code to adhere to ROBLOX’s inherit frame-loop

RunService provides multiple ways to do this. Heartbeat fires every frame after physics simulation completes, RenderStepped fires every frame prior to rendering, and Stepped fires every frame before physics simulations. There’s separate use cases for all three (read the article if you want to know more), but basic use cases include client-side manipulation of the camera.

8 Likes

Runservice is a loop that usually runs at the players fps, there are multiple different varients like heartbeat which runs after the physics simulation, stepped / render stepped which runs prior to the physics simulation. Etc. (MARK AS SOLLUTION PLEASE)

1 Like

Even though it may seem like the events are loops, they aren’t.

3 Likes

RunService acts like a loop and runs similar to while loops, It doesn’t cause your script exhausted if it was timeout which is why I never use while loops for anything again, You can also disconnect the event of RunService when you want the script to stop running, good for implementing NPCs character if they die or any stuff that requires rendering.

1 Like

I already know this, I meant like a loop. Thanks for your irrelvant non-contributive input.

Just correcting you, I don’t know what you do and don’t know. ¯\_(ツ)_/¯

Oh so runservice is a pretty much permanent replacement for while loops? Should I consider this approach as well?

it’s not a replacement actually, it’s useful only in certain situations like looping to find objects when reached at the Magnitude, it’s also a fix to solve the exhaustion of the script if the machine didn’t initialize in the time.

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