:IsClient()
, :IsServer()
and :IsStudio()
functions are used for checking where is code running at.
For example if you run a game on studio with a script inside ServerScriptService
with a line containing:
print(game:GetService("RunService"):IsClient(), game:GetService("RunService"):IsServer(), game:GetService("RunService"):IsStudio())
it will output to console as “false true true” since script itself runs on server and on studio at the same time so both :IsStudio()
and :IsServer()
functions returns true
.
If you try the same thing but with a localscript inside somewhere where it can run it will output to console as “true false true” since :IsClient()
returns true
when used in a localscript and vice versa with :IsServer()
.
Of course that’s not the only use for RunService
. There are 3 important events it contains which are Stepped
, RenderStepped
and Heartbeat
.
Stepped
event fires fires every frame before physics simulation takes effect.
Heartbeat
is same except it fires after every frame which physics simulation is completed for that frame.
Both Stepped
and Heartbeat
events fires 60 times in a second on server under normal circumstances and on client unless client’s computer can’t handle the game properly which may slow down how fast does these events fire.
RenderStepped
event on other hand fires every frame before frame gets rendered and RenderStepped
’s fire rate is also dependent to client’s computer when used on client.
Edit (11/02/2021(DD/MM/YYYY)):
Stepped
, Heartbeat
and RenderStepped
events will be deprecated soon once new 4 events are added to RunService
. Here is the updated version:
PreRender
: Equivalent of old RenderStepped
event. Fires at every frame, after user input is handled and before rendering operation of frame starts. Both PreRender
and RenderStepped
can be only used on localscripts or modulescripts required by localscripts and fire rate of the event is dependent on clients FPS rate. This is the 1st event that fires, out of 4.
PreAnimation
: This is the only truly new event out of the 4 new events. It fires before humanoid animations are applied. This fires after PreRender
event.
PreSimulation
: Equivalent of old Stepped
event. It fires before simulation of physics starts. This is the 3rd event that fires after PreAnimation
event.
PostSimulation
: Equivalent of old Heartbeat
event. It fires after simulation of physics finished. This is the event that fires in last place.
NOTE: These events are not added to API yet. Do not try to use it in new work.
Source: https://twitter.com/MaximumADHD/status/1357532484154580995