RunServiceクラス

クラスサービス(game:GetService("RunService")で取り出す)Instance.newでは作れない日本語解説あり

ひとことで言うと

ゲームの1フレームごとに処理を実行するためのサービスです。パーツを回し続けるなど、なめらかに動かし続けたいときに使います。

公式の説明(英語):Service responsible for all runtime activity and progression of time.

使用例

回り続けるパーツ
Script置く場所:パーツの中
local RunService = game:GetService("RunService")
local part = script.Parent :: BasePart
part.Anchored = true

RunService.Heartbeat:Connect(function(deltaTime)
	part.CFrame = part.CFrame * CFrame.Angles(0, math.rad(90) * deltaTime, 0)
end)

スクリプトは、Luauの型チェック(luau-lsp)で確認しています。

クラスの関係

受け継いでいるクラス:Object → Instance → RunService

プロパティ(1)

名前と書き方説明
RunState
RunService.RunState: RunState
The current run state of the game's simulation.

メソッド(18)

名前と書き方説明
BindToAnimation
RunService:BindToAnimation(function: Function, frequency: StepFrequency, priority: int): RBXScriptConnection
Binds a custom function to be called at a fixed frequency before Animators update when fixed simulation is enabled, or immediately before BindToSimulation callbacks otherwise.
BindToAnimationParallel
RunService:BindToAnimationParallel(function: Function, frequency: StepFrequency, priority: int): RBXScriptConnection
Binds an Actor-scoped function to run in parallel at a fixed frequency after serial Class.RunService:BindToAnimation()|BindToAnimation() callbacks.
BindToRenderStep
RunService:BindToRenderStep(name: string, priority: int, function: Function): ()
Given a string name of a function and a priority, this method binds the function to RunService.PreRender.
BindToSimulation
RunService:BindToSimulation(function: Function, frequency: StepFrequency, priority: int): RBXScriptConnection
Binds a custom function to be called at a fixed frequency which is independent of the frame rate.
BindToSimulationParallel
RunService:BindToSimulationParallel(function: Function, frequency: StepFrequency, priority: int): RBXScriptConnection
Binds an Actor-scoped function to run in parallel at a fixed frequency after serial Class.RunService:BindToSimulation()|BindToSimulation() callbacks.
GetPredictionStatus
RunService:GetPredictionStatus(context: Instance): PredictionStatus
Checks the PredictionStatus of a specific context instance, useful for debugging scripts affecting multiple instances where some might be predicted and others might not.
IsClient
RunService:IsClient(): boolean
クライアントで実行されているかを調べます。Returns whether the current environment is running on the client.
IsEdit
RunService:IsEdit(): boolean
Returns whether the current environment is in Edit mode.
IsResimulating
RunService:IsResimulating(): boolean
Returns whether the client is currently in a resimulation step after a misprediction in the server authority model.
IsRunMode
RunService:IsRunMode(): boolean
Returns whether a **Run** playtest has been initiated in Studio.
IsRunning
RunService:IsRunning(): boolean
Returns whether the experience is currently running.
IsServer
RunService:IsServer(): boolean
サーバーで実行されているかを調べます。Returns whether the current environment is running on the server.
IsStudio
RunService:IsStudio(): boolean
Returns whether the current environment is running in Studio.
Pause
RunService:Pause(): ()
Pauses the experience's simulation if it is running, suspending physics and scripts.
Run
RunService:Run(): ()
Runs the game's simulation, running physics and scripts.
SetPredictionMode
RunService:SetPredictionMode(context: Instance, mode: PredictionMode): ()
Sets the prediction mode for an Instance to an PredictionMode value.
Stop
RunService:Stop(): ()
Stops the experience's simulation if it is running.
UnbindFromRenderStep
RunService:UnbindFromRenderStep(name: string): ()
Unbinds a function that was bound to the render loop using Class.RunService:BindToRenderStep().

イベント(9)

名前と書き方説明
Heartbeat
RunService.Heartbeat(deltaTime: double)
毎フレーム、物理の計算のあとに発生するイベントです。前のフレームからの経過時間(秒)が渡されます。Fires every frame, after the physics simulation has completed.
Misprediction
RunService.Misprediction(time: double, instances: Array, stats: Dictionary)
In the server authority model, fires during prediction when the engine detects that the client has diverged from the server's authoritative state. Intended for plugin-based debugging.
PostSimulation
RunService.PostSimulation(deltaTimeSim: double)
Fires every frame, after the physics simulation has completed.
PreAnimation
RunService.PreAnimation(deltaTimeSim: double)
Fires every frame, prior to the physics simulation but after rendering.
PreRender
RunService.PreRender(deltaTimeRender: double)
Fires every frame, prior to the frame being rendered.
PreSimulation
RunService.PreSimulation(deltaTimeSim: double)
Fires every frame, prior to the physics simulation.
RenderStepped
RunService.RenderStepped(deltaTime: double)
毎フレーム、画面を描く前に発生するイベントです(LocalScript専用)。Fires every frame, prior to the frame being rendered.
Rollback
RunService.Rollback(time: double)
In the server authority model, this fires after rolling back the predicted state due to a misprediction, but before resimulation begins.
Stepped
RunService.Stepped(time: double, deltaTime: double)
Fires every frame, prior to the physics simulation.

受け継いでいるメンバー

Instance から受け継いでいるもの(46)

Archivable・Capabilities・IsInSandbox・Name・Parent・PredictionMode・Sandboxed・AddTag・ClearAllChildren・Clone・Destroy・FindFirstAncestor・FindFirstAncestorOfClass・FindFirstAncestorWhichIsA・FindFirstChild・FindFirstChildOfClass・FindFirstChildWhichIsA・FindFirstDescendant・GetActor・GetAttribute・GetAttributeChangedSignal・GetAttributes・GetChildren・GetDebugId・GetDescendants・GetFullName・GetStyled・GetStyledPropertyChangedSignal・GetTags・HasTag・IsAncestorOf・IsDescendantOf・IsPropertyModified・QueryDescendants・RemoveTag・ResetPropertyToDefault・SetAttribute・WaitForChild・AncestryChanged・AttributeChanged・ChildAdded・ChildRemoved・DescendantAdded・DescendantRemoving・Destroying・StyledPropertiesChanged

Object から受け継いでいるもの(4)

ClassName・GetPropertyChangedSignal・IsA・Changed

RunServiceを使う記事

英語の説明とメンバーの一覧は、Roblox Creator Documentation(RunService)をもとにしています(CC BY 4.0)。日本語の解説は、このサイトで独自に書いたものです。

執筆:鈴木孝昌官公庁のWeb・システム開発を担当する現役プロジェクトマネージャー。沖縄マイクラ部 クロスウェーブで、ロブロックス(Roblox)・マインクラフト(マイクラ)・Scratchなどのプログラミングを指導。マイクラカップ沖縄代表チームを指導(第6回・第7回、第7回TBS賞)。
沖縄マイクラ部で、子どもたちにロブロックス(Roblox)やマインクラフト(マイクラ)のプログラミングを教えています。プロフィールと編集方針
Instagramで教室の様子を見る
noteで記事を読む