Wiki entry for the RunService.
Every ~1/60 of a second, a render update happens. Each render update, a bunch of code is run, namely the code involved with rendering the 3D environment on your screen. There's other stuff too, but that is the "rendering" that the name refers to.
If you want to run your own code on each render update, you have 2 options. You can connect to an event, which is the "old way:"
RunService.RenderStepped:connect(function(step)
end)
Or you can bind a callback, which is the "new way:"
local function onRenderStepped()
end
RunService:BindToRenderStepped("renderFunctionName", Enum.RenderPriority.First.Value, onRenderStepped)
RunService:UnbindFromRenderStepped("renderFunctionName")
The new way is basically a fancier version of the old way, they do the same thing but the new way is easier and safer to use, in my opinion.
The render priority enum determines in what order render functions are executed. Higher numbers mean executed later. The wiki entry for the RenderPriority enum is here.
The functions you bind to render stepped are gonna be called really fast, faster than you can make the be called in a normal loop, because wait() can only delay for as little as 1/30 of a second. Make sure whatever functions you bind to render stepped are really fast, because if they aren't, they will actually slow down render updates, making your game lag like crazy.
I want to emphasize that these functions are called only on render updates, not on a 1/60 of a second loop. If no render update happens, your function wont be called. This means if the game is minimized, you wont get render updates.
I hope this helps!
3 comments
RenderStepped basically just runs the code inside the function for as long as the Roblox Player window is focused, for example: I minimize Roblox to view my desktop- The code will not run until I re-focus on the Roblox Player window.
Ahhh ok thanks!
I'm pretty sure that if there were 2 clients, one with a framerate of 60, and one with a framerate of 10, if you were to use the renderstepped function they would be firing the function at different rates.