Items not getting removed from table?

Basically, I’m making a window, which you can block off with wood by clicking on it. It already has 5 ‘wood’ parts inside of it, which become visible when chosen, and after they have become visible, they get removed from the table containing the left over pieces of wood.

My issue is that, it still prints the name of (which means they got chosen to be placed) parts that have already been placed, but I have used table.remove on it.

Script:

script.Parent.MouseClick:Connect(function(plr)
	local currentwood = plr:FindFirstChild("Wood")
	local woods = {}
	for i, wood in ipairs(script.Parent.Parent:GetChildren()) do
		if wood:IsA("Part") and wood.Material == Enum.Material.Wood then
			table.insert(woods, wood)
		end
	end
	
	if currentwood.Value > 1 then
		--local num = math.random(1, #woods)
		local thepart = woods[math.random(1, #woods)]
		print(thepart.Name)
		thepart.Transparency = 0
		table.remove(woods, table.find(woods, thepart))
		--return
	end
end)

The concept might sound a bit confusing, it’s just about the table part.

Try adding another conditional statement that checks the transparency of the part:

	local woods = {}
	for i, wood in ipairs(script.Parent.Parent:GetChildren()) do
		if wood:IsA("Part") and wood.Material == Enum.Material.Wood and wood.Transparency ~= 0 then
			table.insert(woods, wood)
		end
	end

does any of it print? also this reminds me of like a project lazarus game lol

It works! Thanks for your help.

Have a nice day : )

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