Welding hack for tools

Here is a script you can paste in the command bar to make it easier to weld models instead of manually welding things 1 by 1

local Selection = game:GetService("Selection")

for _, tool in ipairs(Selection:Get()) do
	if not tool:IsA("Tool") then continue end

	local handle = tool:FindFirstChild("Handle")
	local model = tool:FindFirstChildOfClass("Model")

	if handle and model then
		local primPart = model.PrimaryPart

		
		if not primPart then
			primPart = model:FindFirstChild("Part")
			model.PrimaryPart = primPart
		end

		if primPart then
			
			for _, part in ipairs(model:GetDescendants()) do
				if part:IsA("BasePart") and part ~= primPart then
					local weld = Instance.new("WeldConstraint")
					weld.Name = "P2PWeld"
					weld.Part0 = primPart
					weld.Part1 = part
					weld.Parent = part
					part.Anchored = false
					part.CanCollide = false 
				end
			end

			-- 2. Weld the PrimaryPart to the Handle
			local handleWeld = Instance.new("WeldConstraint")
			handleWeld.Name = "HandleModelWeld"
			handleWeld.Part0 = handle
			handleWeld.Part1 = primPart
			handleWeld.Parent = primPart

			primPart.Anchored = false
			handle.Anchored = false

			
			
		end
		
	end
end
2 Likes

Stop using ipairs twin, it’s not needed.

4 Likes

Oh wdym can you tell me what to use because ive been using Ipairs for almost all of my codes lol

for i,v in xyz do 
   ...
end
1 Like

Is there any difference as in is I still the number and V is the instance so theres just no ipairs

ipairs stops after the first nil, so gapped arrays won’t be iterated correctly. Generalized iteration also iterates dictionary keys but personally I have never really felt the need to mix dictionary and array.

2 Likes