Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Cowgato 33
1 year ago

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)
0
Cowgato, is your primarypart a basepart or a humanoid? Kingu_Criminal 205 — 1y

3 answers

Log in to vote
0
Answered by 1 year ago

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)

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 Jay123abc2 241 — 1y
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' Cowgato 33 — 1y
0
Cowgato, Is the primarypart of classname basepart? Kingu_Criminal 205 — 1y
Ad
Log in to vote
0
Answered by 1 year ago

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.

0
Hi there. Could you construct an example of what the code should look like with my script please? Thanks Cowgato 33 — 1y
Log in to vote
0
Answered by
Cowgato 33
1 year ago

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.

Answer this question