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

How do I changed the orientation of a model using script?

I've figured out how to change the position of a model using MoveTo, but I am not sure what piece of script will allow me to also change the orientation of the model. (I have already set the primary part for the model which is called 'MainDoor')

script.Parent.Touched:Connect(function()
	game.Workspace.MainDoor:MoveTo(Vector3.new(73.366, 3.843, -7.959))
--line of code to change orientation of MainDoor
	script.Parent:Destroy()
end)

4 comments

0

We were already helping you on your other question... Why did you create a new one?

0

Hi there, I've already solved the problem on the other post recently, but I'm not sure how to change the orientation now.

0

I don't understand why are you using :MoveTo to move a model. Use :SetPrimaryCFrame() instead (altrough it's deprecated). It has much more possibilites.

0

I would like to use CFrame but I don't know how to use it to make it go to the specific coord I want

1 answer

✓ Accepted answer

You can rotate and move models using :PivotTo(). This is function that can be used to make a model to go a CFrame with a set angle. To make the model only rotate, this can be easily done. Try this piece off code:

script.Parent.Touched:Connect(function()
	game.Workspace.MainDoor:MoveTo(Vector3.new(73.366, 3.843, -7.959))
	game.Workspace.MainDoor:PivotTo(game.Workspace.MainDoor:GetPivot() *  CFrame.Angles(math.rad(90,0,0),0,0))
	script.Parent:Destroy()
end)

All that I have added is game.Workspace.MainDoor:PivotTo(game.Workspace.MainDoor:GetPivot() * CFrame.Angles(math.rad(90,0,0),0,0)), so I will explain that now. First, we get the model which is the MainDoor. We then call :PivotTo(). This will be used to change the pivot. In the brackets, we then get the model again and call :GetPivot() to get the model's current pivot. We then times that pivot by a angle cframe, 90, 0, 0. math.rad converts an angle in degrees to radians. This should then rotate the model.

Some useful links:

Edit: I have replaced game.Workspace.MainDoor:PivotTo(game.Workspace.MainDoor:PivotTo:GetPivot * CFrame.Angles(math.rad(90,0,0),0,0)), with game.Workspace.MainDoor:PivotTo(game.Workspace.MainDoor:GetPivot() * CFrame.Angles(math.rad(90,0,0),0,0)), so I will explain that now. to fix a error

2 comments

0

There is an error which underlines (game.Workspace.MainDoor:PivotTo:GetPibot * CFrame.Angles(math.rad(90,0,0),0,0))

0

Oops - Thats my blame from copy and pasting, Fixed it.

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