How to make part rotate 90 degrees

local PivotPoint = CFrame.new(script.Parent.Position)
local Part = script.Parent
local OpenValue = script.Parent.Parent.Parent:WaitForChild("Open")

OpenValue.Value = false

local AngleRotation = 1

local WorldPartCFrame = PivotPoint * CFrame.Angles(0, math.rad(AngleRotation), 0)
local ObjectPartCFrame = WorldPartCFrame:ToObjectSpace(Part.CFrame)

local function Close()
	WorldPartCFrame = WorldPartCFrame * CFrame.Angles(0, math.rad(1), 0) 
	Part.CFrame = WorldPartCFrame * ObjectPartCFrame 
end

local function Open()
	WorldPartCFrame = WorldPartCFrame * CFrame.Angles(0, math.rad(-AngleRotation), 0) 
	Part.CFrame = WorldPartCFrame * ObjectPartCFrame 
end


local MoveTask
local MoveDebounce = false

local function Move()
	if OpenValue.Value == true then
		
		MoveDebounce = true
		repeat
			Close()
			task.wait()
		until Part.Orientation.Z >= 90
		
		Part.CFrame = CFrame.Angles(0, math.rad(90), 0) 
		MoveDebounce = false
		
	elseif OpenValue.Value == false then
		
		MoveDebounce = true
		repeat
			Open()
			task.wait()
		until Part.Orientation.Z >= -90
		
		Part.CFrame = CFrame.Angles(0, math.rad(-90), 0) 
		MoveDebounce = false
		
	end
end

OpenValue:GetPropertyChangedSignal("Value"):Connect(function()
	if MoveDebounce == true then
		task.cancel(MoveTask)
		MoveTask = task.spawn(Move)
	elseif MoveDebounce == false then
		MoveTask = task.spawn(Move)
	end
end)

When the open Value is changed, the part will rotate. The rotation is perfect fine , HOWEVER, i only want it to rotate for 90 degrees, hyowever, I do not know how to check when the Z axis will = 90, and above.

For those who do not know what i am talking about, i placed this in my script so you can know abit of what im talking about. I know its wrong but it should give sense on what im talking about

until Part.Orientation.Z >= -90

4 Likes

Please explain exactly what you want to happen.

If you just want the part to rotate slowly 90 degrees for open and -90 for close why not just use a tween door?

If you search the forums for ‘tween door’ you’ll find a few posts about how to do it.

3 Likes

its a script to rotate a door when a value is changed. a tween means that the door will rotate but at variable speeds?? cause if the door is closinng halfway and then the value changes, the rotation speed will incrteases if it was using tween?

1 Like

until Part.Orientation >= Vector3.new(0,0,-90)

2 Likes

= Vector3.new(0,0,-90)

does not work

1 Like

Why aren’t you just tweening it?

You could probably make a script to check the distance between the rotations and just make it estimate a normalized time

1 Like

can i just get help on what property i should check the part to know if its exceeding 90 degrees? for the

`> until Part.Orientation.Z >= -90

`

1 Like

You are changing the Y and you’re checking the Z
image

1 Like

Use CFrame.fromAxisAngle().

CFrame | Documentation - Roblox Creator Hub

1 Like

Thanks i didnt notice it. However, what the problem is is that how do i check how many degrees a part is rotated on a single axis from a cframe or whatever

1 Like

Ah, so what you want is a door that can be changed direction half way through it’s travel?
A HingeConstraint set to Servo, a Weld, or a Motor may be a good option for you.