CFrames being weird and I don't know what the issue is

I’m trying to have a sword be placed into the players hand when I equip it, everything works correctly at orientation 0,0,0 but if you turn at all the sword isn’t in the correct place at all.
Code:

Sword:SetPrimaryPartCFrame(char:FindFirstChild("Right Arm").CFrame)
Sword.Sword.CFrame = Sword.Sword.CFrame * CFrame.Angles(0, math.rad(0), math.rad(180))
Sword.Handle.CFrame = Sword.Handle.CFrame * CFrame.Angles(0, math.rad(90), *math.rad(-90))
Sword.Sword.Position = Sword.Sword.Position + Vector3.new(-.1,-.868,-.05)
Sword.Handle.Position = Sword.Handle.Position + Vector3.new(-.1,-.868,-0.05)
2 Likes

How do you position it? Is it done every frame, or similar?
Either way, I think using welds would be a better use case for this:

local GripWeld = Instance.new("Weld")
GripWeld.Part0 = char:FindFirstChild("Right Arm")
GripWeld.Part1 = Sword.Handle
GripWeld.C0 = CFrame.new(0, 1, 0) * CFrame.Angles(0, math.rad(90), *math.rad(-90))
GripWeld.Parent = Sword.Handle

local SwordWeld = Instance.new("Weld")
SwordWeld.Part0 = Sword.Handle
SwordWeld.Part1 = Sword.Sword
-- i don;t know what your sword model looks like so im guessing based off your code
SwordWeld.C0 = CFrame.new(-.1,-.868,-.05) * CFrame.Angles(0, math.rad(0), math.rad(180))
SwordWeld.Parent = Sword.Sword

Ok, sorry for the confusion, I didn’t explain well. I’ve already done that, after setting the CFrame I welded the Handle part to the players right arm. But, based on where you’re looking the orientation of the sword would be different. For example, if the players orientation was 0,0,0 the sword would look right. But if you turn at all it messed up the swords orientation.

can you post more of your script then i need to see how it works exactly

This is the entire script:

local Sword = game.ReplicatedStorage.Assets.VFX.Vergil.Sword:Clone()
		Sword.Parent = char
		Sword:SetPrimaryPartCFrame(char:FindFirstChild("Right Arm").CFrame)
		Sword.Sword.CFrame = Sword.Sword.CFrame * CFrame.Angles(0, math.rad(0), math.rad(180))
		Sword.Handle.CFrame = Sword.Handle.CFrame * CFrame.Angles(0, math.rad(90), math.rad(-90))
		Sword.Sword.Position = Sword.Sword.Position + Vector3.new(-.1,-.868,-.05)
	Sword.Handle.Position = Sword.Handle.Position + Vector3.new(-.1,-.868,-0.05)
		local weld = Instance.new("Weld")
		weld.Part0 = Sword.Handle
		weld.Part1 = char:FindFirstChild("Right Arm")
		weld.C0 = weld.Part0.CFrame:ToObjectSpace(weld.Part1.CFrame)
		weld.Parent = weld.Part0

It really only is supposed to position itself in the correct spot and then weld to the players arm, but the positioning gets messed up if you arent at orientation 0,0,0

is that actually the entire script or are you lying, im only trying to help you

It’s the entire relevant part of the script. It sets the position and the welds it to the arm, it’s simple.
I’m sure
the problem is something i dont understand about CFrames, so i wanted someones opinion on it. The rest of the script is just equipping the tool.

I was able to figure it out on my own

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