Question about RunService

Hello! I got a few questions about RunService, what does runService.RenderStepped:Connect(function() do?
It’s a kind of loop?
Also, can you give me some examples about RunService.Stepped, RunService.RenderStepped? I don’t kinda udnerstand it, anyway thanks

3 Likes

To quote the developer hub:

The RunService contains methods and events for time-management as well as for managing the context in which a game or script is running. Methods like IsClient , IsServer , IsStudio , can help you determine where Lua code is running. These methods are useful for ModuleScripts that could be required by both the client and server. In addition, you can use IsStudio to add special behavior for in-studio testing.

RunService has a variety of functions to help check what environment the code is running in (IsClient/IsEdit/IsRunMode/IsRunning/IsServer/IsStudio/etc)

The functions you’re talking about relate to rendering. Here’s a description of what they do:

RunService.RenderStepped(delta)

This event fires prior to every frame render (hence render). It includes one argument, called step- this is the time elapsed since the previous frame was rendered.
This function can be used to monitor frames per second.

It can be used for loops, but should be avoided for code that isn’t front-facing related (e.g. UI code should be connected to RenderStepped as it’s to do with rendering) as it’s tied to the FPS.

RunService.Heartbeat(delta)

The Heartbeat event fires every frame , after the physics simulation has completed. The step argument indicates the time that has elapsed since the previous frame.

It’s basically the same as RenderStepped, but fires after the physics simulation is complete.

RunService.Stepped(delta)

Ditto all others, it just fires before the physics simulation

RunService:BindToRenderStep(name, priority, function)

This function can be used to connect a callback to render stepped at specific priority levels. This can be useful for events such as input or camera controls (see chart below)


Here’s a helpful chart from @Fractality_alt

11 Likes