So Im making a round based survival game with terrain and Im trying to find a way to weld all parts that are touching to each other on command and so far i have made this script

local function weldBetween(a, b)
	--Make a new Weld and Parent it to a.
	local weld = Instance.new("ManualWeld", a)
	--Get the CFrame of b relative to a.
	weld.C0 = a.CFrame:inverse() * b.CFrame
	--Set the Part0 and Part1 properties respectively
	weld.Part0 = a
	weld.Part1 = b
	--Return the reference to the weld so that you can change it later.
	return weld
end





for _,part in pairs(game.Workspace:GetDescendants()) do
   if part:IsA("Part") then     ---- or part:IsA("MeshPart") 
        for _,touching in pairs(part:GetTouchingParts()) do
            --weld(part,touching)
			local weldOne = weldBetween(part, touching)
        end
    end
end

this should work but for whatever reason, it does nothing and doesn't bring up any errors, I have searched for a way to do this for countless hours. any help is appreciated!

1 comment

0

Please use the lua code block so we can understand this. When asking the question, there is a blue symbol that has the word "lua" on it. Put this code in between it and we might be able to read it easier.