Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why use RunService?

So I've seen on top of the game people putting variables for a RunService.... Something like this

local run = game:GetService('RunService')

I want to know if the code above is necessary or if it is really needed in a script or perhaps it would help with debugging? Thank you for checking this out! I hope someone can answer this because I never use RunService.

1 comment

1 answer

RunService does a variety of things, but no, you don't need to put it into a variable.

This works fine:

if game:GetService('RunService'):IsClient() then
	game:GetService('RunService').RenderStepped:connect(function() print("client step") end)
else
	game:GetService('RunService').Stepped:connect(function() print("server step") end)
end

But this also works, and in some cases, works faster:

local run = game:GetService('RunService')
if run:IsClient() then
	run.RenderStepped:connect(function() print("client step") end)
else
	run.Stepped:connect(function() print("server step") end)
end

This discussion is preserved as it was. New answers, comments, and votes are closed.