Modelクラス

クラス日本語解説あり

ひとことで言うと

いくつものパーツをひとまとめにする入れ物です。キャラクターや建物など、複数の部品でできたものはModelになっています。

公式の説明(英語):Models are container objects, meaning they group objects together. They are best used to hold collections of Class.BasePart|BaseParts and have a number of functions that extend their functionality.

使用例

ふれたプレイヤーをテレポートさせる
Script置く場所:テレポート台のパーツの中(行き先にTeleportTargetという名前のパーツを置く)
local pad = script.Parent :: BasePart
local target = workspace:WaitForChild("TeleportTarget") :: BasePart

pad.Touched:Connect(function(hit)
	local character = hit.Parent
	if character and character:IsA("Model") and character:FindFirstChildWhichIsA("Humanoid") then
		character:PivotTo(target.CFrame + Vector3.new(0, 5, 0))
	end
end)

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

クラスの関係

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

このクラスを受け継ぐクラス:Actor、BackpackItem、ProceduralModel、Status、WorldRoot

プロパティ(5)

名前と書き方説明
LevelOfDetail
Model.LevelOfDetail: ModelLevelOfDetail
Sets the level of detail on the model for experiences with instance streaming enabled.
ModelStreamingMode
Model.ModelStreamingMode: ModelStreamingMode
Controls the model streaming behavior on Class.Model|Models when instance streaming is enabled.
PrimaryPart
Model.PrimaryPart: BasePart
モデルの基準になるパーツ。PivotToなどで動かすときの基準になります。The primary part of the Model, or nil if not explicitly set.
Scale
Model.Scale: float
Editor-only property used to scale the model around its pivot. Setting this property will move the scale as though Class.Model:ScaleTo() was called on it.
WorldPivot
Model.WorldPivot: CFrame
Determines where the pivot of a Model which does **not** have a set Model.PrimaryPart is located.

メソッド(9)

名前と書き方説明
AddPersistentPlayer
Model:AddPersistentPlayer(playerInstance: Player): ()
Sets this model to be persistent for the specified player. Class.Model.ModelStreamingMode|ModelStreamingMode must be set to Enum.ModelStreamingMode|PersistentPerPlayer for behavior to be changed as a result of addition.
GetBoundingBox
Model:GetBoundingBox(): Tuple
Returns a description of a volume that contains all parts of a Model.
GetExtentsSize
Model:GetExtentsSize(): Vector3
Returns the size of the smallest bounding box that contains all of the Class.BasePart|BaseParts in the Model, aligned with the Model.PrimaryPart if it is set.
GetPersistentPlayers
Model:GetPersistentPlayers(): List<Player>
Returns all the Player objects that this model object is persistent for. Behavior varies based on whether this method is called from a Script or a LocalScript.
GetScale
Model:GetScale(): float
Returns the canonical scale of the model, which defaults to 1 for newly created models and will change as it is scaled via Class.Model:ScaleTo().
MoveTo
Model:MoveTo(position: Vector3): ()
Moves the Class.Model.PrimaryPart|PrimaryPart to the given position. If a primary part has not been specified, the root part of the model will be used.
RemovePersistentPlayer
Model:RemovePersistentPlayer(playerInstance: Player): ()
Makes this model no longer persistent for the specified player. Class.Model.ModelStreamingMode|ModelStreamingMode must be set to Enum.ModelStreamingMode|PersistentPerPlayer for behavior to be changed as a result of removal.
ScaleTo
Model:ScaleTo(newScaleFactor: float): ()
モデル全体の大きさを、指定した倍率に変えます。Sets the scale factor of the model, adjusting the sizing and location of all descendant Instances such that they have that scale factor relative to their initial sizes and locations when scale factor was 1.
TranslateBy
Model:TranslateBy(delta: Vector3): ()
Shifts a Model by the given Vector3 offset, preserving the model's orientation. If another BasePart or Terrain already exists at the new position then the Model will overlap said object.

受け継いでいるメンバー

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

Origin・Pivot Offset・GetPivot・PivotTo

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

Modelを使う記事

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

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