Table won't remove another table from itself

Hello. I’m trying to make a system which makes terrain that had been modified by another script restore itself. It works well except once the terrain restores itself, it restores previously restored terrain because of save which is a table containing the terrain values such as position, material and such.
I’ve tried to prevent this with table.remove as you can see below, but it doesn’t work.

while wait(10) do
	for i,save in terrsave do
		if (save[1] - wheelpart.Position).Magnitude > 30 then
			terrain:FillBall(save[1], save[2], save[3])
			table.remove(terrsave, table.find(terrsave, save))
			
			print(save)
			wait(.1)
		end
	end
end

print(save) still prints after save was removed with table.remove(terrsave, table.find(terrsave, save))

1 Like

Within the for-loop, you aren’t actually changing the value of save, instead only whether or not it is in the table. You should instead be checking the terrsave table (potentially using table.find) in order to determine if the table has been successfully removed.

i dont want to check or change the value of save. i want to remove save entirely, but table.remove(terrsave, table.find(terrsave, save)) is failing to do so.

I’m not sure if it IS failing to do so - I believe that your method of confirming whether it failed or not is invalid. Can you please try replacing

print(save)

with

print(table.find(terrsave, save))

and tell me what the output is?

smart. yeah that was the problem i was making. thank you.

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