How do I rotate a part using cframe based of world space

So, I’m making a placement system and it’s going well except for the rotating. it’s really weird and rotates weirdly. I honestly have no idea why it’s happening.

like if I try to rotate with the Y then R it just rotates so weirdly.

main code:

local Prompt = Model:FindFirstChildWhichIsA("ProximityPrompt")
	local CanPlace = true
	local SelectionBox = Instance.new("SelectionBox",Model)
	SelectionBox.Adornee = Model
	SelectionBox.LineThickness = .01
	SelectionBox.Visible = false
	SelectionBox.Color3 = Color3.fromRGB(0, 255, 0)
	local Rotation = CFrame.Angles(0,0,0)
	local YRotation = 0
	local ZRotation = 0
	local XRotation = 0
	local Event = game.ReplicatedStorage.Events.Drag.OnServerEvent:Connect(function(Player,Pos)
		if Player.Name == Model:FindFirstChildWhichIsA("StringValue").Value then
			if (Player.Character.PrimaryPart.Position - Pos).Magnitude > 5 then
				Pos = Player.Character.PrimaryPart.Position + (Pos - Player.Character.PrimaryPart.Position).Unit * 5
			end
			game:GetService("TweenService"):Create(Model.PrimaryPart,TweenInfo.new(.1),{CFrame = CFrame.new(Pos) * CFrame.Angles(math.rad(XRotation),math.rad(YRotation),math.rad(ZRotation))}):Play()
			local TouchingParts = {}
			for _, part in pairs(Model:GetDescendants()) do
				if part:IsA("BasePart") then
					local EV = part.Touched:Connect(function() end)
					local TP = part:GetTouchingParts()
					for _, int in pairs(TP) do
						table.insert(TouchingParts,int)
					end
					EV:Disconnect()
				end
			end
			if #TouchingParts > 0 then
				CanPlace = true
				SelectionBox.Color3 = Color3.fromRGB(0, 255, 0)
			else
				CanPlace = false
				SelectionBox.Color3 = Color3.fromRGB(255, 0, 0)
			end
		end
	end)
	local Event3 = game.ReplicatedStorage.Events.Place.OnServerEvent:Connect(function(Player,Input,Mobile)
		if Player.Name == Model:FindFirstChildWhichIsA("StringValue").Value then
			if Input == Enum.KeyCode.R then
				YRotation += 15
			end
			if Input == Enum.KeyCode.T then
				ZRotation += 15
			end
			if Input == Enum.KeyCode.Y then
				XRotation += 15
			end
		end
	end)
	end)

Ok I figured out the issue.

How do I rotate something not relative to its rotation

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.