Welding using script?

Hi,

So i wanted to weld every part inside my gun using script and don’t do i manually.

I did this:

for _, u in pairs(game.ReplicatedStorage.weapons:GetChildren()) do
	local receiver = u:WaitForChild("receiver")
	for _, v in pairs(u:GetDescendants()) do
		if v:IsA("BasePart") then
			v.CanCollide = false
			v.Anchored = false
			
			local weld = Instance.new("Weld") --Also tryed WeldConstraint
			weld.Part0 = v
			weld.Part1 = receiver
			weld.Name = weld.Part0.Name.." > "..weld.Part1.Name
			
			weld.Parent = v
		end
	end
end

Heres what i got (BAD):

This makes every part to be in same place.

But if i do it manually (create welds and setting it by myself) i will get this (GOOD):

How to fix this?

After the first line here, add this line:

weld.C0 = receiver.CFrame:ToObjectSpace(v.CFrame)
1 Like

still a bit not good.

Will try to search more info about welds

Try using a WeldConstraint instead of a normal weld, and see if that works.

1 Like

sadly still don’t work. have no idea why…

This supposed to be good but…

Maybe try it like this?

local weld = Instance.new("WeldConstraint") 

weld.Part0 = receiver
weld.Part1 = v
weld.Name = weld.Part0.Name.." > "..weld.Part1.Name
			
weld.Parent = receiver

still nothing… oof will probably do everything manually

Maybe try welding everything first, then unanchoring them?