Need help with SetPrimaryPartCFrame Bug?

For context I’m making a game that uses weapons currently I’m using a weld (for now, later I will change it to joint for animations) and I need to change the position of the weapon to the player hand with an offset. However then using SetPrimaryPartCFrame an error shows this

Invalid argument #2 (Vector3 expected, got CFrame)

This is weird because I thought it needed an CFrame and not a Vector3? As it says Set CFrame.
Is this a bug, something wrong with my code or bug at roblox’s end?

Here is the code

local function WeaponON()
	ChoosenWeapon.Parent = Char
	ChoosenWeapon:SetPrimaryPartCFrame(CFrame.new(RightArm.CFrame + WeaponsInfo.WeaponOffSet[ChoosenWeapon.Name]))
	NewWeld(RightArm,ChoosenWeapon)
end

ANd here is how the weld is create (currently causing no issues)

local function NewWeld(part0,part1)
	local NewWeld = Instance.new("WeldConstraint")
	NewWeld.Part0 = part0
	NewWeld.Part1 = part1
	NewWeld.Parent = part0
end

This is the moduleScript storing the data for weapons Offsets ( but there is currently only one weapon)

module.WeaponOffSet = {
	["Basic"] = CFrame.new(0,0,-1)
}

Any insight would be very helpful and thank you.

(btw I very much know I can use tools instead, however I would like to do this instead because I want it part of the character and not to show up in the player hotbar without disabling the hotbar)

Your basically trying to add a CFrame to another CFrame which doesn’t work directly as it expects Vector3 data for positional math
To solve this issue i’d recommend multiplying the arms CFrame with the CFrame offset so something like this:

ChoosenWeapon:SetPrimaryPartCFrame(RightArm.CFrame * WeaponsInfo.WeaponOffSet[ChoosenWeapon.Name])

I hope this helps.

Interesting, I do remember that now (due to me working a lot in unity more recently. But now there is an issue with New? something to do with invalid argument #1?

But thank you for reminding me

Oof I forgot the CFrame.new() within the code
Maybe that will fix it?

Thank you, that seems to be the issue

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