It works fine until I try to remove the character from the table when the character dies. How can I fix this to find the position of the character then remove it from the table?
In table.remove, the second parameter is the position of what you want to remove. So if you use table.find like this: table.remove(characters,table.find(characters,char)) it should work.
There’s probably better ways to do it, but this is what I would do.
You actually can put an object in a table since script functioned as intended but I just had to know how to find it’s position in the table which I didn’t know how, Your script would also not work
As others have pointed out, table.remove requires an index. The reason why is that you could have multiple of the same element in a table, so table.remove wouldn’t know which one to remove. We can get the index by using table.find, which returns the index of the first element that it’s searching for.
Or in another way you could chek all the objects in the table cheking if the object is equal to the character and if it is break the loop and remove the index.
This thread become pretty long. @Wigglyaa already gave the answer at the very top.
@Moneypro456789 objects can be stored in tables just like into variables. Instances are userdata, and they are referenced with a special Roblox’s reference ID. Similarly, printing tables in log mode displays their memory address. Tables are objects too.