So i'm trying to make a script that detects when a player enters & leaves by putting their name in a table. Problem is i'm not sure if you can use table.remove() to remove a value,
local players = {} game.Players.ChildAdded:connect(function(plr) table.insert(players, ""..plr.Name) end) game.Players.ChildRemoved:Connect(function(plr) table.remove(players, ""..plr.Name) end)
Any tips on how I can get it to remove the child's name off of the table when they leave?
You can't remove an item from a table by its name, you can only do it by its position. What you could do is cycle through the table until you find the position that matches the player's name, and remove that position.
Here is what I mean:
local players = {} game.Players.ChildAdded:connect(function(plr) table.insert(players, ""..plr.Name) end) game.Players.ChildRemoved:Connect(function(plr) table.remove(players, ""..plr.Name) for i=1, #players do if plr.Name == players[i] then table.remove(players, i) end end end)