Kinda new to using tables but how would i remove a random part from it

i’m just kinda new to using tables and need some help

–Here’s The Script

		for _, part in pairs(Build1:GetChildren()) do
			part.Anchored = true
			PartStoreTable[#PartStoreTable+1] = part
			local randomPart = PartStoreTable[math.random(#PartStoreTable)]
			table.remove(?)
		end

The question mark is just a placeholder for what i should put there.

PartStoreTable[math.random(#PartStoreTable)] = nil

or

table.remove(PartStoreTable, table.find(PartStoreTable, PartStoreTable[math.random(#PartStoreTable)))

The table.remove function takes two parameters: the table to be affected, and the index to remove.

local randomIndex = math.random(1, #PartStoreTable)
table.remove(PartStoreTable, randomIndex)

i got one more question, how would i get it to collect all children of Build1 in the table without repeating numbers / repeating itself.

local childrenTable = {}

for _, child in pairs(Build1:GetChildren()) do
	table.insert(childrenTable, child)
end

This would add all children of Build1 to the childrenTable table. As long as it’s not executed more than once, the childrenTable table should have no duplicates.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.