SetPrimaryPartCFrame() problem

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want the gun to be in the player’s hand, like this:
    supposed

  2. What is the issue? Include screenshots / videos if possible!
    This happens everytime:
    whathappens

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried some stuff, but nothing worked yet

function characterMod(weapon, character)
	local model = Models:FindFirstChild(weapon):Clone()
	model.Parent = game.ReplicatedFirst
	
	--//weld\\--
	
	for i,v in model:GetDescendants() do
		if v:IsA('BasePart') and v ~= model.PrimaryPart then
			local weld = Instance.new('WeldConstraint', v)
			weld.Part0 = v
			weld.Part1 = model.PrimaryPart
			weld.Name = "_"..v.Name
			
			v.Anchored = false
		end
	end
	
	local armWeld = Instance.new('WeldConstraint', model.PrimaryPart)
	
	armWeld.Part0 = model.PrimaryPart
	armWeld.Part1 = character:FindFirstChild("Right Arm")
	armWeld.Name = "RightArm"
	
	--//parent\\--
	
	model.PrimaryPart.Anchored = false

	--//cf\\--
	
	model:SetPrimaryPartCFrame(character.HumanoidRootPart.CFrame * model.PrimaryPart.CFrame)
	
	--//parent\\--
	
	model.Parent = character
	
	model.Name = "ThirdPersonGun"
	
end

The weld that connects the primarypart to the arm is what you want to change, mess around with its offset values to get it in the place you want

You should start to consider model:PivotTo(cframe) over SetPrimaryPartCFrame() because the latter is deprecated, and here’s some tips:

set part0 for the gun model
set part1 for the character limb

cframe the weapon before it’s welded otherwise it’s going to float far off in a distance

DON’T use model.PrimaryPart property because it’s a locked reference for the PrimaryPart of the model and changing or accessing properties with that reference will cause silent errors in the future that will drive you crazy. You should use FindFirstChild() 99% of cases.

local armWeld = Instance.new(‘WeldConstraint’, model.PrimaryPart)

DON’T use the second argument of Instance.new() especially for any type of ‘Weld’, the reason is simply because it’s slower and will cause what mentioned before:

“Will set the weld before you can cframe it and cause the model to float away in the distance.”

Always set the properties first before parenting the Instance