เรียนรู้
Engine Class
Model

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


สรุป
วิธีการ
AddPersistentPlayer(playerInstance: Player):()
BreakJoints():()
เลิกใช้แล้ว
breakJoints():()
เลิกใช้แล้ว
GetModelCFrame():CFrame
เลิกใช้แล้ว
GetModelSize():Vector3
เลิกใช้แล้ว
GetPrimaryPartCFrame():CFrame
เลิกใช้แล้ว
MakeJoints():()
เลิกใช้แล้ว
makeJoints():()
เลิกใช้แล้ว
move(location: Vector3):()
เลิกใช้แล้ว
MoveTo(position: Vector3):()
moveTo(location: Vector3):()
เลิกใช้แล้ว
RemovePersistentPlayer(playerInstance: Player):()
ResetOrientationToIdentity():()
เลิกใช้แล้ว
ScaleTo(newScaleFactor: number):()
SetIdentityOrientation():()
เลิกใช้แล้ว
SetPrimaryPartCFrame(cframe: CFrame):()
เลิกใช้แล้ว
TranslateBy(delta: Vector3):()
สมาชิกที่ได้รับทอด
ได้รับทอดโดย
ตัวอย่างโค้ด
การสร้างโมเดลพื้นฐาน
local function groupObjects(objectTable)
local model = Instance.new("Model")
for _, object in pairs(objectTable) do
object.Parent = model
end
return model
end
local objects = {
Instance.new("Part"),
Instance.new("Part"),
}
groupObjects(objects)

เอกสารอ้างอิงเกี่ยวกับ API
คุณสมบัติ
LevelOfDetail
การรักษาความปลอดภัยของปลั๊กอิน
อ่านพร้อมๆ กัน
Model.LevelOfDetail:Enum.ModelLevelOfDetail

ModelStreamingMode
อ่านพร้อมๆ กัน
Model.ModelStreamingMode:Enum.ModelStreamingMode

PrimaryPart
อ่านพร้อมๆ กัน
Model.PrimaryPart:BasePart
ตัวอย่างโค้ด
การโยนลูกเต๋า
-- สร้างแบบจำลองลูกเต๋าที่มีสองด้านและเชื่อมต่อพวกมันเข้าด้วยกัน
local diceModel = Instance.new("Model")
diceModel.Name = "ChanceCube"
local diceTop = Instance.new("Part")
diceTop.Size = Vector3.new(4, 2, 4)
diceTop.Position = Vector3.new(0, 1, 0)
diceTop.Color = Color3.new(0, 0, 1)
diceTop.Parent = diceModel
local diceBottom = diceTop:Clone()
diceBottom.Position = Vector3.new(0, -1, 0)
diceBottom.Color = Color3.new(1, 0, 0)
diceBottom.Parent = diceModel
local weld = Instance.new("WeldConstraint")
weld.Part0 = diceTop
weld.Part1 = diceBottom
weld.Parent = diceModel
-- ยกลูกเต๋าขึ้นไปในอากาศเหนือจุดเริ่มต้นของ workspace (ไม่ต้องการพาร์ตหลัก)
diceModel.Parent = workspace
diceModel:PivotTo(CFrame.new(0, 10, 0))
-- ตั้งค่าพาร์ตหลักก่อนการจำลองทางกายภาพ
-- หากไม่มีบรรทัดนี้ สคริปต์จะแสดงผลเหมือนเดิมเสมอและ bounding box ของแบบจำลองจะไม่เปลี่ยนการจัดแนว
diceModel.PrimaryPart = diceTop
-- รอสักครู่ก่อนที่จะโยนลูกเต๋า (ให้มันตั้งอยู่บนพื้น)
for i = 5, 1, -1 do
print("โยนลูกเต๋าใน...", i)
task.wait(1)
end
diceTop:ApplyAngularImpulse(Vector3.new(15000, 1000, 5000))
diceTop:ApplyImpulse(Vector3.new(0, 3000, 0))
task.wait(1)
-- รอให้การโยนเสร็จสิ้น
while diceTop.AssemblyLinearVelocity.Magnitude > 0.1 or diceTop.AssemblyAngularVelocity.Magnitude > 0.1 do
task.wait()
end
-- รับการจัดแนวของลูกเต๋า ซึ่งได้รับผลกระทบจากพาร์ตหลัก
local orientation = diceModel:GetBoundingBox()
if orientation.YVector.Y > 0.5 then
print("มันคือเด็กชาย!")
else
print("มันคือแม่ของเขา!")
end

Scale
ไม่ซ้ำ
ไม่สามารถเขียนสคริปต์
อ่านพร้อมๆ กัน
Model.Scale:number

WorldPivot
ไม่ซ้ำ
อ่านพร้อมๆ กัน
Model.WorldPivot:CFrame
ตัวอย่างโค้ด
รีเซ็ตพิวท
local function resetPivot(model)
local boundsCFrame = model:GetBoundingBox()
if model.PrimaryPart then
model.PrimaryPart.PivotOffset = model.PrimaryPart.CFrame:ToObjectSpace(boundsCFrame)
else
model.WorldPivot = boundsCFrame
end
end
resetPivot(script.Parent)

วิธีการ
AddPersistentPlayer
Model:AddPersistentPlayer(playerInstance:Player):()
พารามิเตอร์
playerInstance:Player
ค่าเริ่มต้น: "nil"
ส่งค่ากลับ
()

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

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

GetBoundingBox
Model:GetBoundingBox():Tuple
ส่งค่ากลับ

GetExtentsSize
Model:GetExtentsSize():Vector3
ส่งค่ากลับ
ตัวอย่างโค้ด
โมเดล GetExtentsSize
local model = Instance.new("Model")
model.Parent = workspace
local RNG = Random.new()
for _ = 1, 5 do
local part = Instance.new("Part")
part.Anchored = true
part.Size = Vector3.new(RNG:NextNumber(0.05, 5), RNG:NextNumber(0.05, 5), RNG:NextNumber(0.05, 5))
part.Parent = model
end
print(model:GetExtentsSize())

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

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

GetPersistentPlayers
Model:GetPersistentPlayers():{Player}
ส่งค่ากลับ

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

GetScale
การเข้าถึงการจำลองสถานการณ์
Model:GetScale():number
ส่งค่ากลับ
ตัวอย่างโค้ด
การแทนที่โมเดลด้วย PivotTo และ ScaleTo
local CollectionService = game:GetService("CollectionService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- หาทุกโมเดลที่มีแท็กที่เราต้องการแทนที่
local items = CollectionService:GetTagged("Tree")
local newModel = ReplicatedStorage.FancyTreeReplacementModel
for _, item in items do
-- สร้างรายการใหม่และปรับขนาด / ตำแหน่งให้ตรงกับที่เก่าของมัน
local newItem = newModel:Clone()
newItem:ScaleTo(item:GetScale())
newItem:PivotTo(item:GetPivot())
-- เพิ่มแท็กเดียวกันให้กับการแทนที่
CollectionService:AddTag(newItem, "Tree")
-- ลบรายการเก่าและเพิ่มรายการใหม่เข้าไป
newItem.Parent = item.Parent
item:Destroy()
end

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

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

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

MoveTo
Model:MoveTo(position:Vector3):()
พารามิเตอร์
position:Vector3
ส่งค่ากลับ
()
ตัวอย่างโค้ด
โมเดล MoveTo
local START_POSITION = Vector3.new(-20, 10, 0)
local END_POSITION = Vector3.new(0, 10, 0)
local model = Instance.new("Model")
model.Parent = workspace
local part1 = Instance.new("Part")
part1.Size = Vector3.new(4, 4, 4)
part1.Position = START_POSITION
part1.Anchored = true
part1.BrickColor = BrickColor.new("Bright yellow")
part1.Parent = model
local part2 = Instance.new("Part")
part2.Size = Vector3.new(2, 2, 2)
part2.Position = START_POSITION + Vector3.new(0, 3, 0)
part2.Anchored = true
part2.BrickColor = BrickColor.new("Bright blue")
part2.Parent = model
model.PrimaryPart = part1
model.Parent = workspace
local obstruction = Instance.new("Part")
obstruction.Name = "Obstruction"
obstruction.Size = Vector3.new(10, 10, 10)
obstruction.Position = Vector3.new(0, 10, 0)
obstruction.Anchored = true
obstruction.BrickColor = BrickColor.new("Bright green")
obstruction.Parent = workspace
task.wait(3)
model:MoveTo(END_POSITION)

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

RemovePersistentPlayer
Model:RemovePersistentPlayer(playerInstance:Player):()
พารามิเตอร์
playerInstance:Player
ค่าเริ่มต้น: "nil"
ส่งค่ากลับ
()

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

ScaleTo
Model:ScaleTo(newScaleFactor:number):()
พารามิเตอร์
newScaleFactor:number
ส่งค่ากลับ
()

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

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

TranslateBy
Model:TranslateBy(delta:Vector3):()
พารามิเตอร์
delta:Vector3
ส่งค่ากลับ
()
ตัวอย่างโค้ด
โมเดลแปลโดย
local START_POSITION = Vector3.new(-20, 10, 0)
local END_POSITION = Vector3.new(0, 10, 0)
local model = Instance.new("Model")
local part1 = Instance.new("Part")
part1.Size = Vector3.new(4, 4, 4)
part1.CFrame = CFrame.new(START_POSITION) * CFrame.Angles(0, math.rad(45), 0)
part1.Anchored = true
part1.BrickColor = BrickColor.new("Bright yellow")
part1.Parent = model
local part2 = Instance.new("Part")
part2.Size = Vector3.new(2, 2, 2)
part2.CFrame = part1.CFrame * CFrame.new(0, 3, 0)
part2.Anchored = true
part2.BrickColor = BrickColor.new("Bright blue")
part2.Parent = model
model.PrimaryPart = part1
model.Parent = workspace
local obstruction = Instance.new("Part")
obstruction.Name = "Obstruction"
obstruction.Size = Vector3.new(10, 10, 10)
obstruction.Position = Vector3.new(0, 10, 0)
obstruction.Transparency = 0.5
obstruction.Anchored = true
obstruction.BrickColor = BrickColor.new("Bright green")
obstruction.Parent = workspace
task.wait(3)
-- ใช้ TranslateBy เพื่อเลื่อนโมเดลเข้าไปในโครงสร้าง
model:TranslateBy(END_POSITION - START_POSITION)

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