Rotation issue for build system

This video shows me testing out the rotation feature of my build system. Here is the code:

uis.InputBegan:Connect(function(input, process)
	if selected ~= false and previewpart ~= nil then -- if there is a build selected and a preview part, then
		if input.KeyCode == Enum.KeyCode.R then -- tells script to rotate along x axis
			if uis:IsKeyDown(Enum.KeyCode.LeftShift) then -- if shift is held down, rotate the part in the opposite direction
				previewpart.Orientation += Vector3.new(15, 0, 0)
			else
				previewpart.Orientation -= Vector3.new(15, 0, 0)
			end
		elseif input.KeyCode == Enum.KeyCode.T then -- tells script to rotate along y axis
			if uis:IsKeyDown(Enum.KeyCode.LeftShift) then
				previewpart.Orientation += Vector3.new(0, 15, 0)
			else
				previewpart.Orientation -= Vector3.new(0, 15, 0)
			end
		elseif input.KeyCode == Enum.KeyCode.Y then -- tells script to rotate along the Z axis
			if uis:IsKeyDown(Enum.KeyCode.LeftShift) then
				previewpart.Orientation += Vector3.new(0, 0, 15)
			else
				previewpart.Orientation -= Vector3.new(0, 0, 15)
			end
		end
	end
end)

I’m running into an issue with the orientation property. The selected part in the video is the white preview part shown on my mouse, you can see its’ orientation property in the properties window.

While rotating the part, I noticed the orientation property ranges from -180 to 180 instead of 0 to 360 degrees. This causes some weird glitches with the rotation, as seen in the end of the video (I was only pressing R at the end of the video)

Why not use CFrame.Angles and just multiply the CFrame by math.rad(15) for whatever coordinate. You won’t have to worry about those bounds then

1 Like

Ok, quick update. I tried this idea but I forgot to use math.rad() to convert radians to degrees

Here’s my current script incase anyone who finds this post is having the same issue as me:

uis.InputBegan:Connect(function(input, process)
	if selected ~= false and previewpart ~= nil then
		if input.KeyCode == Enum.KeyCode.R then
			if uis:IsKeyDown(Enum.KeyCode.LeftShift) then
				previewpart.CFrame = previewpart.CFrame * CFrame.Angles(math.rad(-15), 0, 0)
			else
				previewpart.CFrame = previewpart.CFrame * CFrame.Angles(math.rad(15), 0, 0)
			end
		elseif input.KeyCode == Enum.KeyCode.T then
			if uis:IsKeyDown(Enum.KeyCode.LeftShift) then
				previewpart.CFrame = previewpart.CFrame * CFrame.Angles(0, math.rad(-15), 0)
			else
				previewpart.CFrame = previewpart.CFrame * CFrame.Angles(0, math.rad(15), 0)
			end
		elseif input.KeyCode == Enum.KeyCode.Y then
			if uis:IsKeyDown(Enum.KeyCode.LeftShift) then
				previewpart.CFrame = previewpart.CFrame * CFrame.Angles(0, 0, math.rad(-15))
			else
				previewpart.CFrame = previewpart.CFrame * CFrame.Angles(0, 0, math.rad(15))
			end
		end
	end
end)