game.Players.PlayerRemoving:connect(function(Player)
table.remove(_G.Plyrs, Player.Name)
end)
This is what I am doing but it's expecting a number rather than a string. Anyway to remove a player from a table easily?
game.Players.PlayerRemoving:connect(function(Player)
table.remove(_G.Plyrs, Player.Name)
end)
This is what I am doing but it's expecting a number rather than a string. Anyway to remove a player from a table easily?
That's because the table.remove method's second argument is the index value, meaning it won't search through the table to remove what you want..
Say I had this table;
tb = {1,2,3,4,5}
And I did;
tb = {"Hi","Bob",2}
print(table.concat(tb," "))
> Hi Bob 2
table.remove(tb,2)
print(table.concat(tb," "))
> Hi 2
It won't remove the index in the table named 2 it will remove the index in the table at that value.
So to fix your problem then you could do this;
val = nil
for i,v in pairs(_G.Plyrs)
if v == Player.Name then
val = i
end
end
--Now the variable 'val' will have the index number that you need to remove the desired object from your table.
table.remove(_G.Plyrs,val)
-Goulstem
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
This worked in playsolo but not online. It says on the "for i,v in pairs(_G.Plyrs)" that it was expecting a table but got nil.
Uhhm, I'm not exactly sure what the problem would be. That means the the table doesn't exist anymore.. Maybe this is loading at the same time a the creation of the table, add a wait(5) at the top of the script.