Engine Class
RunService
Summary
Properties
Methods
BindToRenderStep(name: string,priority: number,function: function):() |
BindToSimulation(function: function,frequency: Enum.StepFrequency,priority: number):RBXScriptConnection |
GetPredictionStatus(context: Instance):Enum.PredictionStatus |
Pause():() |
Reset():() |
Run():() |
SetPredictionMode(context: Instance,mode: Enum.PredictionMode):() |
Stop():() |
UnbindFromRenderStep(name: string):() |
Events
Heartbeat(deltaTime: number):RBXScriptSignal |
Misprediction(time: number,instances: {any},stats: Dictionary):RBXScriptSignal |
PostSimulation(deltaTimeSim: number):RBXScriptSignal |
PreAnimation(deltaTimeSim: number):RBXScriptSignal |
PreRender(deltaTimeRender: number):RBXScriptSignal |
PreSimulation(deltaTimeSim: number):RBXScriptSignal |
RenderStepped(deltaTime: number):RBXScriptSignal |
Rollback(time: number):RBXScriptSignal |
Stepped(time: number,deltaTime: number):RBXScriptSignal |
API Reference
Properties
Methods
BindToRenderStep
Returns
()
Code Samples
Frame Moving in Circle
local RunService = game:GetService("RunService")
-- How fast the frame ought to move
local SPEED = 2
local frame = script.Parent
frame.AnchorPoint = Vector2.new(0.5, 0.5)
-- A simple parametric equation of a circle
-- centered at (0.5, 0.5) with radius (0.5)
local function circle(t)
return 0.5 + math.cos(t) * 0.5, 0.5 + math.sin(t) * 0.5
end
-- Keep track of the current time
local currentTime = 0
local function onRenderStep(deltaTime)
-- Update the current time
currentTime = currentTime + deltaTime * SPEED
-- ...and the frame's position
local x, y = circle(currentTime)
frame.Position = UDim2.new(x, 0, y, 0)
end
-- This is just a visual effect, so use the "Last" priority
RunService:BindToRenderStep("FrameCircle", Enum.RenderPriority.Last.Value, onRenderStep)
--RunService.RenderStepped:Connect(onRenderStep) -- Also works, but not recommendedRunService Custom Function
local RunService = game:GetService("RunService")
local function checkDelta(deltaTime)
print("Time since last render step:", deltaTime)
end
RunService:BindToRenderStep("Check delta", Enum.RenderPriority.First.Value, checkDelta)Bind and Unbind a Function
local RunService = game:GetService("RunService")
-- Step 1: Declare the function and a name
local NAME = "Print Hello"
local function printHello()
print("Hello")
end
-- Step 2: Bind the function
RunService:BindToRenderStep(NAME, Enum.RenderPriority.First.Value, printHello)
-- Step 3: Unbind the function
RunService:UnbindFromRenderStep(NAME)BindToSimulation
RunService:BindToSimulation(
Parameters
| Default Value: "Hz30" |
| Default Value: 2000 |
Returns
Code Samples
Synchronizing a Part's Color Property
local RunService = game:GetService("RunService")
local Workspace = game:GetService("Workspace")
local somePart:BasePart = Workspace:WaitForChild("Part")
RunService:BindToSimulation(function(deltaTime: number)
local syncdColor = Color3.fromHSV(math.fmod(time(), 1.0), 1.0, 1.0)
somePart:SetAttribute("SyncdColor", syncdColor)
end)
RunService.RenderStepped:Connect(function(deltaTime: number)
local syncdColor = somePart:GetAttribute("SyncdColor")
somePart.Color = syncdColor
end)GetPredictionStatus
Parameters
Returns
Pause
RunService:Pause():()
Returns
()
Reset
Run
RunService:Run():()
Returns
()
SetPredictionMode
Parameters
Returns
()
Stop
RunService:Stop():()
Returns
()
Events
Misprediction
Parameters
PostSimulation
PreAnimation
PreRender
PreSimulation
Stepped