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

My weld module keeps bugging, please provide information ?

local module = {}

function WeldParts(parts)
local prev
	for i = 1,#parts do 
	if (parts[i]:IsA("BasePart")) then 
		if (prev ~= nil)then 
			local weld = Instance.new("Weld") 
			weld.Part0 = prev 
			weld.Part1 = parts[i] 
			weld.C0 = prev.CFrame:inverse() 
			weld.C1 = parts[i].CFrame:inverse() 
			weld.Parent = prev 
		end 
		prev = parts[i] 
	end 
end
end


function module:FormWeldToChar(char, pos, model)
	local ready = false
	local posp = nil
	
	local forweldparts = {}
	
	for _, v in pairs(char:GetDescendants()) do
		if v.Name == pos and v:IsA("BasePart") then
			ready = true
			posp = v
		end
	end
	if ready == true then
		posp.Anchored = true
		wait()
		model:SetPrimaryPartCFrame(posp.CFrame)
		for _, d in pairs(model:GetDescendants()) do
			if d:IsA("BasePart") and d.Name ~= "tref" then
				table.insert(forweldparts, d)
				table.insert(forweldparts, posp)
			end
		end
		wait()
		WeldParts(forweldparts)
		for i = 1, #forweldparts do
			forweldparts[i].Parent = char
		end
		wait()
		model:Destroy()
		for i = 1, #forweldparts do
			forweldparts[i].Anchored = false
		end
	end
end

return module

that is the module, it works fine in small games, however when in large games it bugs out and the offset of the weld gets messed up, the module is called like so;

Module:FormWeldToChar(CHAR, "Torso", Model_Clone)

I would like help revising this module so the offset of the model-parts don't get messed up when welded, all the parts of the model clone are positioned and the "tref" functions as a canvas for easy-placement.

1 answer

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