So I'm having bit of an issue here. This is my script so far. Also the prints are just for debugging and so you can see what it is.
--source removed
Whoever enters a region (a 2048x2048 part is used to define regions), will be added to a table. That part completely works.
The issue I'm having is when someone leaves a region, which works from my IsTouch script, I don't know what row their name is on, using table.remove.
Table.remove doesn't remove strings, it removes rows. Look below for an example.
--source removed
The example above will remove the second thing in the list, since it's the second in a row. If you were to print the entire table after removing "2", it would print "wont be removed" twice.
My main issue is figuring out what the names row is on, since everyones name is different and they can be added at any time, how can I detect which row the name is on?
I was going to write this as a comment but figured I may as well put this as an answer. As tiraner300 said in the comments, you'll want to loop through the table to find the desired name.
When the player leaves the region, you know that player left? If so, you'll need to use a for loop to find their name in the table by doing the following:
local playerWhoLeft = "Someones_Name" for iterator, name in pairs(PlayersTouching) do if playerWhoLeft == name then table.remove(PlayersTouching, iterator) break end end
The iterator is the position of the name that matched the playerWhoLeft. The loop starts at the first element when iterator = 1 and increases by 1 for each name being checked. The break ends the loops when you already have found your player because there is no longer a point in traversing the table.