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