Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does my model not move with this script? (I have already set the primary part)

Hello

I am trying to move a model using script but for some reason, it is not working. ('Door' is the model. I have set the model's primary part to the main part inside the model already)

script.Parent.Touched:Connect(function()
	game.Workspace.Door:MoveTo(Vector3.new(87.065, 3.843, -16.842))
	script.Parent:Destroy()
end)

1 comment

0

Cowgato, is your primarypart a basepart or a humanoid?

3 answers

✓ Accepted answer

You cannot move a model like that, you must move the primary part of the model instead. I also believe MoveTo only works with humanoids. try:

script.Parent.Touched:Connect(function()
	game.Workspace.Door.PrimaryPart.Position = Vector3.new(87.065, 3.843, -16.842)
	script.Parent:Destroy()
end)

3 comments

0

You can also use :PivotTo(CFrame here) to move a model that does not have a primary part. https://developer.roblox.com/en-us/api-reference/function/PVInstance/PivotTo

0

Hi there, Unfortunately, the script still doesn't work. I get an error message on line 2 saying: Workspace.EventDoor.Script:2: attempt to index nil with 'Position'

0

Cowgato, Is the primarypart of classname basepart?

Someone else suggested using Model.PrimaryPart.Position, but I suggest you use Model:SetPrimaryPartCFrame(CFrame) if you are trying to move parts and keep constant offset.

1 comment

0

Hi there. Could you construct an example of what the code should look like with my script please? Thanks

Sorry. I figured out the issue. The script was correct but all my other models were named Door. To fix this issue, I simply changed my main door model to another name.

This discussion is preserved as it was. New answers, comments, and votes are closed.