CFrame not being affected by CFrame.Angles()

Got this script here for a throwable shield im working on, im trying to rotate it 90 degrees onto its side but for some reason it doesn’t rotate?

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local char = plr.Character or plr.CharacterAdded:Wait()

local HumRoot = char:WaitForChild("HumanoidRootPart")

local TweenSerivice = game:GetService("TweenService")
local RunService = game:GetService("RunService")

mouse.Button1Down:Connect(function ()
	local viewmodel = game.Workspace.ViewmodelFolder:FindFirstChild("Viewmodel")
	local LeftArm = viewmodel:FindFirstChild("Left Arm")

	if viewmodel then
		local shield = viewmodel:FindFirstChild("Shield")
		if shield then
			shield.Parent = game.Workspace
			LeftArm.LeftWeapon:Destroy()
			shield.PrimaryPart.CanCollide = true
			shield.PrimaryPart.Anchored = true
			shield.PrimaryPart.CFrame = HumRoot.CFrame * CFrame.Angles(math.rad(90),0,0)
			
			local Tween = TweenSerivice:Create(shield.PrimaryPart, TweenInfo.new(0.5, Enum.EasingStyle.Sine), {CFrame = HumRoot.CFrame * CFrame.new(0,0,-50) * CFrame.Angles(math.rad(90),0,0)})
			Tween:Play()
			Tween.Completed:Connect(function ()
				--local Tween2 = TweenSerivice:Create(shield.PrimaryPart, TweenInfo.new(0.5, Enum.EasingStyle.Sine), {CFrame = HumRoot.CFrame})
				--Tween2:Play()
				local connection
				local alphaADD = 0

				connection = RunService.RenderStepped:Connect(function ()

					shield.PrimaryPart.CFrame = shield.PrimaryPart.CFrame:Lerp(HumRoot.CFrame * CFrame.Angles(math.rad(90),0,0), 0.1 + alphaADD)
					alphaADD += 0.01

					local magnitude = (HumRoot.Position - shield.PrimaryPart.Position).Magnitude

					if connection and magnitude < 0.5 then 
						print("YES")
						connection:Disconnect()
					end
				end)

			end)

		end
	end
end)

Try playing around with the angles a bit.

shield.PrimaryPart.CFrame = HumRoot.CFrame * CFrame.Angles(math.rad(90),0,0)

Play around and try different combinations like CFrame.Angles(math.rad(90),math.rad(90),0) or CFrame.Angles(math.rad(-90),0,math.rad(90))
I’m not sure that much how CFrame.Angles works so I wouldn’t know why it does this but it doesn’t work the same way as vectors.

1 Like

Try creating a brand new cframe for the shield instead of multiplying the rotation by the root’s position

1 Like

I used this instead:

HumRoot.CFrame * CFrame.Angles(math.rad(90),math.rad(90),0)

it worked i guess,? but im kinda confused on how.

Will it still work if you only rotate it on the y-axis? If yes then you were probably just rotating on the wrong axis

1 Like

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