Hello, I have Weld script that activates when the player picks certain item in the inventory. But when it copies the armor (Model) from the replicated storage and into the player I get a glitchy result. I hope you guys can help me out:

Glitchy armor

local function weld(a,b)
    local w = Instance.new("ManualWeld", b)
    w.Name = a.Name.."_Weld_"..b.Name
    w.C0 = a.CFrame:inverse() * b.CFrame
    w.Part0 = a
    w.Part1 = b
end


local function weldModel(item_model, char)
    for i,v in pairs(item_model:GetChildren()) do
	    if v:IsA("BasePart") or v:IsA("UnionOperation") or v:IsA("MeshPart") then
		    local weldTo = char:FindFirstChild(v.Name)
		    if weldTo then
			    weld(v, weldTo)
		    end
		    v.Anchored = false 
	    end
    end
end


_G.EquipItem = function(char)
    local item = game.ReplicatedStorage.Items:FindFirstChild(item_name)
    if item then
	    if char:findFirstChild(item_name) then
		    char:findFirstChild(item_name):Destroy()
	    end
	    for i,v in pairs(item:getChildren()) do
		    if v:IsA("Model") then
			    local item_model = v:Clone()
			    item_model.Parent = char
			    item_model:SetPrimaryPartCFrame(char.Head.CFrame)
			    weldModel(item_model,char)
		    end
	    end
    end
end

4 comments

0

provide more context to what the different things are, like what is a and what is b and _G and so on

0

_G is a global function but that ain't important, if you know how functions work you know where a and b come from. (I use it in the weldModel function) I belive the problem is somewhere around setting the primary part CFrame and weld at lines 33,34

0

i've had problems like this before, maybe try adding wait() before the welding part/s (line 5,6 or/and 33,34)

0

but if that isn't what u mean then can u add more details. cuz im assuming that it doesnt weld.