Make a model have a specific position

Making a mesh or a part follow a play, for example, is pretty simple.
But how can I make a model follow a player?

The only thing I can think of, which sounds absurd is to note every part’s position and then write the code one by one. This sounds excessive, is there any others solution?

https://developer.roblox.com/en-us/api-reference/property/Model/PrimaryPart

https://developer.roblox.com/en-us/api-reference/function/Model/MoveTo

https://developer.roblox.com/en-us/api-reference/function/Model/SetPrimaryPartCFrame

Primary Part moves the whole model?

There is another way to do it, which does not involve changing every part’s position as that is impractical and could potentially take ages. Models have a property called “PrimaryPart”. You are able to change the position of a model by adjusting the position of the PrimaryPart, which will move the entire model along with the PrimaryPart.

To set a PrimaryPart, you can either do it through a script or manually. To do it manually, click on the “PrimaryPart” property of the model, then click a part inside the model. This will set the PrimaryPart of the model to whatever part you clicked. To do it in a script, you can do something as simple as the following:

game.Workspace.Model.PrimaryPart = game.Workspace.Model.Part -- obviously change it.

Then, you can use :SetPrimaryPartCFrame() in order to change the CFrame of the PrimaryPart which will move the entire model. I have linked the API Reference to help you further.

Another method you can use is Welding the model to the PrimaryPart and then move set the CFrame of the PrimaryPart
Example:

local function WeldModelToPrimaryPart(model)
	local primaryPart = model.PrimaryPart
	
	for _, part in next, model:GetDescendants() do
		if (part ~= primaryPart and part:IsA("BasePart")) then
			local weld = Instance.new("Weld")
			weld.Part0 = primaryPart
			weld.Part1 = part
			weld.C0 = primaryPart.CFrame:inverse() * part.CFrame
			weld.Parent = part
			part.Anchored = false
		end
	end
end

local model = workspace.TestModel
WeldModelToPrimaryPart(model)
model.PrimaryPart.CFrame = CFrame.new(0, 0, 0)

Using this method will prevent this from happening

1 Like