เรียนรู้
Engine Class
RunService
ไม่สามารถสร้าง
บริการ
ไม่ซ้ำ

*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่


สรุป
คุณสมบัติ
สมาชิกที่ได้รับทอด

เอกสารอ้างอิงเกี่ยวกับ API
คุณสมบัติ
ClientGitHash
อ่านอย่างเดียว
ไม่ซ้ำ
การรักษาความปลอดภัยของสคริปต์ Roblox
อ่านพร้อมๆ กัน
ความสามารถ: Basic
RunService.ClientGitHash:string

RunState
ไม่ซ้ำ
การรักษาความปลอดภัยของปลั๊กอิน
อ่านพร้อมๆ กัน
ความสามารถ: Basic
RunService.RunState:Enum.RunState

วิธีการ
BindToRenderStep
ความสามารถ: Basic
RunService:BindToRenderStep(
name:string, priority:number, function:function
):()
พารามิเตอร์
name:string
priority:number
function:function
ส่งค่ากลับ
()
ตัวอย่างโค้ด
การเคลื่อนที่ของเฟรมในวงกลม
local RunService = game:GetService("RunService")
-- ความเร็วที่เฟรมควรเคลื่อนที่
local SPEED = 2
local frame = script.Parent
frame.AnchorPoint = Vector2.new(0.5, 0.5)
-- สมการพาราเมตริกง่ายๆ ของวงกลม
-- ที่อยู่กลางที่ (0.5, 0.5) และมีรัศมี (0.5)
local function circle(t)
return 0.5 + math.cos(t) * 0.5, 0.5 + math.sin(t) * 0.5
end
-- ติดตามเวลาปัจจุบัน
local currentTime = 0
local function onRenderStep(deltaTime)
-- อัปเดตเวลาปัจจุบัน
currentTime = currentTime + deltaTime * SPEED
-- ...และตำแหน่งของเฟรม
local x, y = circle(currentTime)
frame.Position = UDim2.new(x, 0, y, 0)
end
-- นี่เป็นเพียงเอฟเฟกต์ภาพ ดังนั้นใช้ "Last" priority
RunService:BindToRenderStep("FrameCircle", Enum.RenderPriority.Last.Value, onRenderStep)
--RunService.RenderStepped:Connect(onRenderStep) -- ก็ใช้ได้ แต่ไม่แนะนำ
ฟังก์ชันที่กำหนดเองของ RunService
local RunService = game:GetService("RunService")
local function checkDelta(deltaTime)
print("เวลาตั้งแต่ขั้นตอนการเรนเดอร์ครั้งล่าสุด:", deltaTime)
end
RunService:BindToRenderStep("ตรวจสอบ delta", Enum.RenderPriority.First.Value, checkDelta)
ผูกและยกเลิกฟังก์ชัน
local RunService = game:GetService("RunService")
-- ขั้นตอนที่ 1: ประกาศฟังก์ชันและชื่อ
local NAME = "พิมพ์สวัสดี"
local function printHello()
print("สวัสดี")
end
-- ขั้นตอนที่ 2: ผูกฟังก์ชัน
RunService:BindToRenderStep(NAME, Enum.RenderPriority.First.Value, printHello)
-- ขั้นตอนที่ 3: ยกเลิกฟังก์ชัน
RunService:UnbindFromRenderStep(NAME)

BindToSimulation
ความสามารถ: Basic
RunService:BindToSimulation(
function:function, frequency:Enum.StepFrequency, priority:number
พารามิเตอร์
function:function
ค่าเริ่มต้น: "Hz30"
priority:number
ค่าเริ่มต้น: 2000
ส่งค่ากลับ
ตัวอย่างโค้ด
การซิงโครไนซ์คุณสมบัติสีของชิ้นส่วน
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
ความสามารถ: Basic
การเข้าถึงการจำลองสถานการณ์
RunService:GetPredictionStatus(context:Instance):Enum.PredictionStatus
พารามิเตอร์
context:Instance
ส่งค่ากลับ

IsClient
เขียนพร้อมๆ กัน
ความสามารถ: Basic
RunService:IsClient():boolean
ส่งค่ากลับ

IsEdit
การรักษาความปลอดภัยของปลั๊กอิน
เขียนพร้อมๆ กัน
ความสามารถ: Basic
RunService:IsEdit():boolean
ส่งค่ากลับ

IsRunMode
เขียนพร้อมๆ กัน
ความสามารถ: Basic
RunService:IsRunMode():boolean
ส่งค่ากลับ

IsRunning
ความสามารถ: Basic
RunService:IsRunning():boolean
ส่งค่ากลับ

IsServer
เขียนพร้อมๆ กัน
ความสามารถ: Basic
RunService:IsServer():boolean
ส่งค่ากลับ

IsStudio
เขียนพร้อมๆ กัน
ความสามารถ: Basic
RunService:IsStudio():boolean
ส่งค่ากลับ

Pause
การรักษาความปลอดภัยของปลั๊กอิน
ความสามารถ: Basic
RunService:Pause():()
ส่งค่ากลับ
()

Reset
เลิกใช้แล้ว

Run
การรักษาความปลอดภัยของปลั๊กอิน
ความสามารถ: Basic
RunService:Run():()
ส่งค่ากลับ
()

SetPredictionMode
ความสามารถ: Basic
RunService:SetPredictionMode(
):()
พารามิเตอร์
context:Instance
ส่งค่ากลับ
()

Stop
การรักษาความปลอดภัยของปลั๊กอิน
ความสามารถ: Basic
RunService:Stop():()
ส่งค่ากลับ
()

UnbindFromRenderStep
ความสามารถ: Basic
RunService:UnbindFromRenderStep(name:string):()
พารามิเตอร์
name:string
ส่งค่ากลับ
()

เหตุการณ์
Heartbeat
ความสามารถ: Basic
RunService.Heartbeat(deltaTime:number):RBXScriptSignal
พารามิเตอร์
deltaTime:number

Misprediction
ความสามารถ: Basic, PluginOrOpenCloud
RunService.Misprediction(
time:number, instances:{any}, stats:Dictionary
พารามิเตอร์
time:number
instances:{any}
ตัวอย่างโค้ด
การคาดการณ์ผิด
local RunService = game:GetService("RunService")
RunService.Misprediction:Connect(function(time, instances, stats)
print(`การคาดการณ์ผิดที่ t={time}, resim={stats.ResimulationTime}s`)
for _, entry in instances do
print(` Instance: {entry.Instance:GetFullName()}`)
if entry.Properties then
for name, values in entry.Properties do
print(` Property '{name}': predicted={values.Predicted}, authoritative={values.Authoritative}`)
end
end
if entry.Attributes then
for name, values in entry.Attributes do
print(` Attribute '{name}': predicted={values.Predicted}, authoritative={values.Authoritative}`)
end
end
end
end)

PostSimulation
ความสามารถ: Basic
RunService.PostSimulation(deltaTimeSim:number):RBXScriptSignal
พารามิเตอร์
deltaTimeSim:number

PreAnimation
ความสามารถ: Basic
RunService.PreAnimation(deltaTimeSim:number):RBXScriptSignal
พารามิเตอร์
deltaTimeSim:number

PreRender
ความสามารถ: Basic
RunService.PreRender(deltaTimeRender:number):RBXScriptSignal
พารามิเตอร์
deltaTimeRender:number

PreSimulation
ความสามารถ: Basic
RunService.PreSimulation(deltaTimeSim:number):RBXScriptSignal
พารามิเตอร์
deltaTimeSim:number

RenderStepped
ความสามารถ: Basic
RunService.RenderStepped(deltaTime:number):RBXScriptSignal
พารามิเตอร์
deltaTime:number

Rollback
ความสามารถ: Basic
RunService.Rollback(time:number):RBXScriptSignal
พารามิเตอร์
time:number
ตัวอย่างโค้ด
การย้อนกลับ
local RunService = game:GetService("RunService")
local stateHistory = {} -- ประวัติสถานะที่กำหนดเองของคุณที่ติดตามต่อขั้นตอนที่กำหนด
RunService.Rollback:Connect(function(time)
-- ทิ้งสถานะที่กำหนดเองใด ๆ ที่ใหม่กว่าขั้นตอนที่ย้อนกลับไป
-- และกู้คืนสถานะที่ขั้นตอนนั้นก่อนที่การจำลองใหม่จะเริ่มต้น
for step, _ in stateHistory do
if step > time then
stateHistory[step] = nil
end
end
end)

Stepped
ความสามารถ: Basic
RunService.Stepped(
time:number, deltaTime:number
พารามิเตอร์
time:number
deltaTime:number

©2026 Roblox Corporation. Roblox, โลโก้ Roblox และ Powering Imagination เป็นส่วนหนึ่งของเครื่องหมายการค้าที่จดทะเบียน และไม่ได้จดทะเบียนของเราในสหรัฐฯ และประเทศอื่นๆ