Tower will not rotate, though nothing is interfering

My tower will not rotate on client side when I press R

uis.InputBegan:Connect(function(input, processed)
	if input.KeyCode == Enum.KeyCode.R then
		print("Pressed R")
		local primpart = place.PrimaryPart
		primpart.CFrame = CFrame.Angles(0, 90, 0)
		print(primpart.Orientation)
	end
end)

It does print “Pressed R” and the Orientation, which is always the same

Nothing else is messing with the CFrame’s orientation except this:

runservice.RenderStepped:Connect(function()
	if place then
		local castpar = RaycastParams.new()
		castpar.FilterType = Enum.RaycastFilterType.Blacklist
		castpar.FilterDescendantsInstances = place:GetDescendants()
		if uis.KeyboardEnabled == true and uis.MouseEnabled == true then --Mouse
			getcast = castmouse()
		elseif uis.KeyboardEnabled == true and uis.TouchEnabled == true then --Touch
			if getcast == nil then
				getcast = workspace:Raycast(camera.CFrame.Position, camera.CFrame.LookVector*1000, castpar)
			end
		elseif uis.TouchEnabled == true and uis.MouseEnabled == true then --Touch/Mouse
			getcast = castmouse()
		end
		if getcast and getcast.Instance then
			if getcast.Instance.Name ~= "CanPlaceOn" then
				canPlace = false
			else
				canPlace = true
			end
			local x = getcast.Position.X
			local y = getcast.Position.Y +(place.PrimaryPart.Size.Y) / 2 + place["Left Leg"].Size.Y
			local z = getcast.Position.Z
			local placecframe = CFrame.new(x, y, z)
			local primpart = place.PrimaryPart
			local orientation = primpart.CFrame.Rotation
			place:SetPrimaryPartCFrame(placecframe * CFrame.Angles(orientation.X, orientation.Y, orientation.Z)) --I think this line is the problem
		end
	end
end)

What’s wrong?

Use place:SetPrimaryPartCFrame(CFrame.Angles(0, math.pi/2, 0))

Always make sure you use math.rad() when dealing with CFrame angles. This includes CFrame.fromOrientation or any other method that would seem to use degrees.

Originally you were setting the primary part CFrame as CFrame.Angles(0, 90, 0), which is wrong. You’re setting the angle of the tower to 90 radians on the Y axis, which translated to degrees is 5156.62016, which as you can see isn’t what you’re aiming for.

1 Like

So something like this?

uis.InputBegan:Connect(function(input, processed)
	if input.KeyCode == Enum.KeyCode.R then
		print("Pressed R")
		place:SetPrimaryPartCFrame(CFrame.Angles(0, math.pi/2, 0))
	end
end)

Because it isn’t working right now.

Yes.

If that doesn’t work, make sure you have nothing interfering with the placement of angles.

Also, your RenderStepped loop is causing the issue as well. Replace the last two lines with this:

			local orientationX, orientationY, orientationZ = primpart.CFrame:ToOrientation()
			place:SetPrimaryPartCFrame(placecframe * CFrame.fromOrientation(orientationX, orientationY, orientationZ)) --I think this line is the problem

Thanks, now it works. I did have to tweak a few things:

place:SetPrimaryPartCFrame(place.PrimaryPart.CFrame * CFrame.Angles(0, math.pi/2, 0))

If I may ask, what is the math behind the math.pi/2 part? I don’t really get it

math.pi is 180 degrees in radians, or 3.14159265…

Since you wanted 90 degrees, math.pi/2 = 90 degrees.

1 Like