Hey guys,
so I've FINALLY decided to put a bit more effort into learning LUA Tables, considering I've been ignoring it for the last few months, and I'm beginning to wonder if it's possible to select a certain string from your table, without knowing the index location.
In this example I've created a table that adds your username once you join, and should remove your name when you leave.
admins = {} game.Players.PlayerAdded:Connect(function(plr) table.insert(admins, plr.Name) print("Inserted user "..plr.Name) end) game.Players.PlayerRemoving:Connect(function(plr) table.remove(admins, plr.Name) print("Removed user "..plr.Name) end)
The joining part works great, yet, obviously, when the user leaves, the table can't select plr.Name because it's not an index value (1,2,3, etc).
Is there any way to work around this issue? PS: This is a SCRIPT, not a LocalScript, trying to expand this to a custom leaderboard in the near future
Thanks!
Hmm well you could do a few things
a dictionary for example:
admins = {} game.Players.PlayerAdded:Connect(function(pl) admins[pl.Name] = true print("Inserted user "..pl.Name) end) game.Players.PlayerRemoving:Connect(function(pl) admins[pl.Name] = nil print("Removed user" ..pl.Name) end)
Or you could actually use a table, you would just have to iterate to get rid of the value:
admins = {} game.Players.PlayerAdded:Connect(function(plr) table.insert(admins, plr.Name) print("Inserted user "..plr.Name) end) game.Players.PlayerRemoving:Connect(function(plr) for index, admin in pairs(admins) do if plr.Name == admin then table.remove(admins, index) break end end print("Removed user "..plr.Name) end)