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 rotate a part 90 degree when clicked on?

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

✓ Accepted answer

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)

4 comments

1

Thank you so much!

0

your welcome

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)

0

I did this at school, so I didnt have time to actually plan this through...

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