Help with moving a model

I know this is very simple but for some reason, my code moves the model above the position

local beans = math.random(1,3)

if beans == 1 then
	script.Parent:MoveTo(Vector3.new(-554.617, 1.732, 66.135))
elseif beans == 2 then
	script.Parent:MoveTo(Vector3.new(-554.622, 1.658, 91.649))
elseif beans == 3 then
	script.Parent:MoveTo(Vector3.new(-616.309, 1.65, 125.028))
end

If anyone knows how to fix this so it won’t just move the model above the position please help.

1 Like

Do you mean, you want to move your model only on ‘x’ or ‘z’ axis? Without changing its height?

Check from this forum. Vector has collision detection. So, if there’s something in the way, it’ll just move upwards so you should use :SetPrimaryPartCFrame() instead.

When I used this it changes the rotation, Is there a way to fix this?

Use PrimaryPartCFrame.

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

Use Primary Part, Like this
Note: Go to the Model Properties press the Primary Part and set it to any child of the Model

script.Parent.PrimaryPart.Position = Vector3.new(-554.617, 1.732, 66.135)
Model:SetPrimaryPartCFrame(CFrame.new(POSITION) * CFrame.Angles(math.rad(),math.rad(),math.rad())) -- put preferred angles in math.rad()

I think that would only move the PrimaryPart and not the other parts that are children of the model

You should use the PivotTo function for moving models. It will move the entire model to the given CFrame.

Model:PivotTo(Cframe.new(POSITION))
2 Likes

Like what @Cens_r mentioned, use the new PivotTo() function as SetPrimaryPartCFrame() is deprecated. No need for welding or unanchoring.

1 Like

I agree, setting a model’s position and preserving its current orientation is fairly trivial.

Model:PivotTo(CFrame.new(0, 0, 0) * Model:GetPivot().Rotation) --If you want to preserve the model's rotation.
2 Likes