Apprendre
Classe de moteur
Model

*Ce contenu est traduit en utilisant l'IA (Beta) et peut contenir des erreurs. Pour consulter cette page en anglais, clique ici.


Résumé
Méthodes
AddPersistentPlayer(playerInstance: Player):()
BreakJoints():()
Déprécié
breakJoints():()
Déprécié
GetModelCFrame():CFrame
Déprécié
GetModelSize():Vector3
Déprécié
MakeJoints():()
Déprécié
makeJoints():()
Déprécié
move(location: Vector3):()
Déprécié
MoveTo(position: Vector3):()
moveTo(location: Vector3):()
Déprécié
RemovePersistentPlayer(playerInstance: Player):()
ScaleTo(newScaleFactor: number):()
SetIdentityOrientation():()
Déprécié
SetPrimaryPartCFrame(cframe: CFrame):()
Déprécié
TranslateBy(delta: Vector3):()
Membres hérités
Échantillons de code
Instantiation de modèle de base
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)

Référence API
Propriétés
LevelOfDetail
Sécurité des plugins
Lecture parallèle
Model.LevelOfDetail:Enum.ModelLevelOfDetail

ModelStreamingMode
Lecture parallèle
Model.ModelStreamingMode:Enum.ModelStreamingMode

PrimaryPart
Lecture parallèle
Model.PrimaryPart:BasePart
Échantillons de code
Lancer de Dés
-- Créer un modèle de dé avec deux moitiés et les attacher ensemble
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
-- Mettre le dé en l'air au-dessus de l'origine de l'espace de travail (ne nécessite pas de partie principale)
diceModel.Parent = workspace
diceModel:PivotTo(CFrame.new(0, 10, 0))
-- Assigner la partie principale avant lasimulation physique
-- Sans cette ligne, le script affichera toujours la même chose et la boîte de délimitation du modèle ne changera pas d'orientation
diceModel.PrimaryPart = diceTop
-- Attendre un peu avant de lancer le dé (laissez-le se stabiliser au sol)
for i = 5, 1, -1 do
print("Lancer le dé dans...", i)
task.wait(1)
end
diceTop:ApplyAngularImpulse(Vector3.new(15000, 1000, 5000))
diceTop:ApplyImpulse(Vector3.new(0, 3000, 0))
task.wait(1)
-- Attendre que le lancer soit complété
while diceTop.AssemblyLinearVelocity.Magnitude > 0.1 or diceTop.AssemblyAngularVelocity.Magnitude > 0.1 do
task.wait()
end
-- Obtenir l'orientation du dé, influencée par la partie principale
local orientation = diceModel:GetBoundingBox()
if orientation.YVector.Y > 0.5 then
print("C'est le garçon !")
else
print("C'est sa mère !")
end

Scale
Non répliqué
Non scriptable
Lecture parallèle
Model.Scale:number

WorldPivot
Non répliqué
Lecture parallèle
Model.WorldPivot:CFrame
Échantillons de code
Réinitialiser le pivot
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)

Méthodes
AddPersistentPlayer
Model:AddPersistentPlayer(playerInstance:Player):()
Paramètres
playerInstance:Player
Valeur par défaut : "nil"
Retours
()

BreakJoints
Déprécié

breakJoints
Déprécié

GetBoundingBox
Model:GetBoundingBox():Tuple
Retours

GetExtentsSize
Model:GetExtentsSize():Vector3
Retours
Échantillons de code
Taille des dimensions du modèle
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
Déprécié

GetModelSize
Déprécié

GetPersistentPlayers
Model:GetPersistentPlayers():{Player}
Retours

GetPrimaryPartCFrame
Déprécié

GetScale
Accès à la simulation
Model:GetScale():number
Retours
Échantillons de code
Substituer un modèle de remplacement en utilisant PivotTo et ScaleTo
local CollectionService = game:GetService("CollectionService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- Trouver tous les modèles avec le tag que nous voulons remplacer
local items = CollectionService:GetTagged("Tree")
local newModel = ReplicatedStorage.FancyTreeReplacementModel
for _, item in items do
-- Créer le nouvel élément et le mettre à l'échelle / le positionner là où l'ancien était
local newItem = newModel:Clone()
newItem:ScaleTo(item:GetScale())
newItem:PivotTo(item:GetPivot())
-- Ajouter le même tag au remplacement
CollectionService:AddTag(newItem, "Tree")
-- Supprimer l'ancien élément et parenté le nouveau
newItem.Parent = item.Parent
item:Destroy()
end

MakeJoints
Déprécié

makeJoints
Déprécié

move
Déprécié

MoveTo
Model:MoveTo(position:Vector3):()
Paramètres
position:Vector3
Retours
()
Échantillons de code
Déplacement du modèle
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("Jaune vif")
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("Bleu vif")
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("Vert vif")
obstruction.Parent = workspace
task.wait(3)
model:MoveTo(END_POSITION)

moveTo
Déprécié

RemovePersistentPlayer
Model:RemovePersistentPlayer(playerInstance:Player):()
Paramètres
playerInstance:Player
Valeur par défaut : "nil"
Retours
()

ResetOrientationToIdentity
Déprécié

ScaleTo
Model:ScaleTo(newScaleFactor:number):()
Paramètres
newScaleFactor:number
Retours
()

SetIdentityOrientation
Déprécié

SetPrimaryPartCFrame
Déprécié

TranslateBy
Model:TranslateBy(delta:Vector3):()
Paramètres
delta:Vector3
Retours
()
Échantillons de code
Modèle TranslateBy
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("Jaune brillant")
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("Bleu brillant")
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("Vert brillant")
obstruction.Parent = workspace
task.wait(3)
-- utiliser TranslateBy pour déplacer le modèle dans l'obstruction
model:TranslateBy(END_POSITION - START_POSITION)

©2026 Société Roblox. Roblox, le logo Roblox et Powering Imagination font partie de nos marques déposées aux États-Unis et dans d'autres pays.