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 5 years ago

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

local topCenter = script.parent
local clickdetector = game.Workspace.Wedge.ClickDetector

clickdetector.MouseClick:Connect(function()
    topCenter.Orientation = Vector3.new(-90,0,0)
end)

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 5 years ago
Edited 5 years ago

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

local turnNum = 0 -- this gets manipulated
local turnAmount = -90 -- change to whatever
local topCenter = script.parent
local clickdetector = game.Workspace.Wedge.ClickDetector

clickdetector.MouseClick:Connect(function()
turnNum = turnNum + turnAmount
    topCenter.Orientation = Vector3.new(turnNum,0,0)
print(topCenter.Orientation) -- remove if desired
end)

1
Thank you so much! WavePain 3 — 5y
0
your welcome EliteRayGawnX2 124 — 5y
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 — 5y
0
I did this at school, so I didnt have time to actually plan this through... EliteRayGawnX2 124 — 5y
Ad

Answer this question