How do I make a script that rotates on the X axis without getting stuck

I want to make a Union rotate around the X axis without getting stuck like in this video.
robloxapp-20210126-1327075.wmv (419.5 KB)

But as you can see in this screenshot mine just gets stuck when it’s at 90 degrees.

This is the script I put in that union:

game:GetService("RunService").Heartbeat:Connect(function(dt)
	script.Parent.Orientation += Vector3.new(45 * dt, 0, 0)
end)

This happens because orientation caps at 90 then starts going on from 90 to 0 but your script keeps increading the orientation vector. You can avoid this by using CFrame and CFrame.Angles() instead of orientation:

game:GetService("RunService").Heartbeat:Connect(function(dt)
	script.Parent.CFrame *= CFrame.Angles(math.rad(45*dt),0,0)
end)
2 Likes

You don’t need a script for that, you can do something like this too, it would probably be better for peformance.