CFrame with wrong value

I want to weld a shotgun on my left arm. And I use the following script.

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local shotgun = ReplicatedStorage.Shotgun

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local RightArm = character:FindFirstChild("Right Arm")
		local shotgunClone = shotgun:Clone()
		if not RightArm or not shotgunClone then return end
		
		shotgunClone.Parent = character
		local motor6D = Instance.new("Motor6D")
		motor6D.Parent = RightArm
		motor6D.Name = "shotgun"
		motor6D.Part0 = RightArm
		motor6D.Part1 = shotgunClone
		motor6D.C0 = CFrame.new(0.011, -1.557, -0.5) * CFrame.Angles(math.rad(90), math.rad(180), 0)
	end)
end)

However, the orientation value is not 90, 180, 0. the value is like this, why? How to fix this?

Everything is right
You need to understand how euler’s math works to use CFrame.fromEulerAnglesXYZ() format (CFrame.Angles)
For now use

CFrame.fromEulerAnglesYXZ(mapth.pi*0.5,math.pi,0)

math.pi = 180 degrees if you dont get it

1 Like

Everything else seemed fine except for when you multiplied the position CFrame with CFrame.Angles(math.rad(90), math.rad(180), 0) which is the equivalent to CFrame.EulerAnglesXYZ(math.pi/2,math.pi,0) or CFrame.fromRotation(math.pi/2,math.pi,0). To convert from degrees to radians, math.rad(90) is the same as math.pi/2 and to convert radians to degrees, math.pi is the same as math.rad(180). The thing is you would have to use an orientation instead of a rotation based on the order of CFrame axes (YXZ vs XYZ). Use CFrame.EulerAnglesYXZ(math.rad(90), math.rad(180), 0) or CFrame.fromOrientation(math.rad(90), math.rad(180), 0).
An example of someone who has dealt with this issue:

Try this:

motor6D.C0 = CFrame.new(0.011, -1.557, -0.5) * CFrame.fromOrientation(math.rad(90), math.rad(180), 0)`
1 Like

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