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

Blacklisting in a weld script?

How would I go about blacklisting models/parts from being welded in this script?

while (not script.Parent.Cloned.Value) do wait() end

local parts = {}

function scan(p)
	for _,v in pairs(p:GetChildren()) do
		if (v:IsA("BasePart")) then
			table.insert(parts,v)
		end
		scan(v)
	end
end

function weld()
	scan(script.Parent)
	local prev
	for _,v in pairs(parts) do
		if (prev) then
			local weld = Instance.new("Weld")
			weld.Part0 = prev
			weld.Part1 = v
			weld.C0 = prev.CFrame:inverse()
			weld.C1 = v.CFrame:inverse()
			weld.Parent = prev
		end
		prev = v
	end
	wait(1)
	for _,v in pairs(parts) do v.Anchored = false end
	script.Parent.Welded.Value = true
end

weld()

1 answer

Roblox recently added Folders to developers' play. They are like Models, except the Parts included won't move together when you interact with them in Edit mode (Roblox Studio), making grouping much easier.

So the Parts you want welded can get placed in a Folder, and the script will only return the children of said Folder. This is technically a whilelist, but it will do the job.

Place this script wherever you want, just make sure the scan() function targets the Folder.

while (not script.Parent.Cloned.Value) do wait() end

local parts = {}

function scan(p) --p, in this case, is the folder that includes the parts to be welded
    for _,v in pairs(p:GetChildren()) do
        if (v:IsA("BasePart")) then
            table.insert(parts,v)
        end
        scan()
    end
end

function weld()
    scan(workspace.ToWeld) --Name the folder whatever you want, just make sure to place welded parts in there. That's pretty much the only change needed. Your script is fine otherwise.
--Also, just in case you didn't know, you can refer to the workspace as i did above.
    local prev
    for _,v in pairs(parts) do
        if (prev) then
            local weld = Instance.new("Weld")
            weld.Part0 = prev
            weld.Part1 = v
            weld.C0 = prev.CFrame:inverse()
            weld.C1 = v.CFrame:inverse()
            weld.Parent = prev
        end
        prev = v
    end
    wait(1)
    for _,v in pairs(parts) do v.Anchored = false end
    script.Parent.Welded.Value = true
end

weld()

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