Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How Could I Weld a Model to The Player's Torso?

Basically I have this backpack model, and inside the model there are multiple parts and unions, as well as this script:

local bp = script.Parent
local Character = script.Parent.Parent
bp.Parent = Character.Torso

bp:SetPrimaryPartCFrame(Character.Torso.CFrame)
for i,v in pairs(bp:GetChildren()) do
	if v:IsA("UnionOperation") or v:IsA("Part") then
		local w = Instance.new("Weld", v)
		w.Part0 = v
		v.CFrame = Character.Torso.CFrame
		w.Part1 = Character.Torso
		w.C0 = v.CFrame
		w.C1 = Character.Torso.CFrame
		v.Anchored = false
		v.CanCollide = false
	end
end

Now this script welds all of the parts to the player's torso, however all of the parts go to the exact same position(Inside the torso). Now after this I had an idea to give each part an offset value to position each part correctly this only changes line 10 of the code: v.CFrame = Character.Torso.CFrame * CFrame.new(v.Offset.Value) This works! BUT the second you rotate your player from the starting rotation, and then try and weld the backpack, the parts gets completely messed up. I'm wondering how I could fix this issue, or maybe there is a better way to weld models to players? This is literally my first time using welds please help!

Here is a video for more clarification: https://www.youtube.com/watch?v=fYBtweAd4qU

1 answer

I think your problem is that you're doing the C0 and C1 incorrectly. I don't entirely understand what they mean, really only how to use them. The C0 should be Part0's offset from Part1, and in this case C1 should be left nil.

Here's two solutions. It should probably be noted that in both I set C0 to (part).CFrame:inverse() * Character.UpperTorso.CFrame. Which in English is the part's cframe negated plus the torso's cframe.

local bp = script.Parent
local Character = script.Parent.Parent

bp:SetPrimaryPartCFrame(Character.Torso.CFrame)
for i,v in pairs(bp:GetChildren()) do
	if v:IsA("BasePart") then
		local w = Instance.new("Weld", v)
		w.C0 = (v.CFrame:inverse() * Character.Torso.CFrame)
		w.Part0 = v
		w.Part1 = Character.Torso
		v.Anchored = false
		v.CanCollide = false
    end
end

This one welds all of the parts to the primary part.

local bp = script.Parent
local Character = script.Parent.Parent

for i,v in pairs(bp:GetChildren()) do -- Weld all parts in the model except the primarypart to the model's primarypart
	if v:IsA("BasePart") and v ~= bp.PrimaryPart then
		local w = Instance.new("Weld", v)
		w.C0 = (v.CFrame:inverse() * bp.PrimaryPart.CFrame)
		w.Part0 = v
		w.Part1 = bp.PrimaryPart
		v.Anchored = false
		v.CanCollide = false
	end
end

bp:SetPrimaryPartCFrame(Character.Torso.CFrame)
local w = Instance.new("Weld", bp.PrimaryPart) -- Weld the PrimaryPart to the player's torso
w.Part0 = bp.PrimaryPart
w.Part1 = Character.Torso
bp.PrimaryPart.Anchored = false
bp.PrimaryPart.CanCollide = false

Side note: Use BasePart in the IsA instead of UnionOperation and Part, as it'll include anything that a human would consider a part (And terrain, for some reason)

This discussion is preserved as it was. New answers, comments, and votes are closed.