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

How do I rotate a part 90 degree when clicked on?

Asked by 6 years ago

I can't figure out how to rotate a part 90 degree after clicked on.

1local topCenter = script.parent
2local clickdetector = game.Workspace.Wedge.ClickDetector
3 
4clickdetector.MouseClick:Connect(function()
5    topCenter.Orientation = Vector3.new(-90,0,0)
6end)

I'm using this code but it only rotates the part once.
I want to be able to rotate it multiple times.

1 answer

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

You need to add # of degrees to the number that the x axis is orientated to.

01local turnNum = 0 -- this gets manipulated
02local turnAmount = -90 -- change to whatever
03local topCenter = script.parent
04local clickdetector = game.Workspace.Wedge.ClickDetector
05 
06clickdetector.MouseClick:Connect(function()
07turnNum = turnNum + turnAmount
08    topCenter.Orientation = Vector3.new(turnNum,0,0)
09print(topCenter.Orientation) -- remove if desired
10end)
1
Thank you so much! WavePain 3 — 6y
0
your welcome EliteRayGawnX2 124 — 6y
1
It's far better practice to use CFrame.Angles if you want to make the rotation occur multiple times. topCenter.CFrame = topCenter.CFrame * CFrame.Angles(math.rad(-90),0,0) SummerEquinox 643 — 6y
0
I did this at school, so I didnt have time to actually plan this through... EliteRayGawnX2 124 — 6y
Ad

Answer this question