I’ve been researching this topic as much as I could, however I can’t find any topic relating to mine, so I’ll make my own
Code:
local playing = {}
game.Players.PlayerAdded:Connect(function(player)
if not table.find(playing, player.Name) then
table.insert(playing, player.Name)
warn('Inserted player directly!')
else
warn('Player is already in the table!')
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
if table.find(playing, plr.Name) then
table.remove(playing, plr.Name)
warn('Player has been removed from Playing Table!')
else
warn('Player is leaving successfully! No table issues')
end
end)
This code is rather simple; It’s supposed to check for any new players, and add them to a table if they aren’t already inside of that table. Then, once they leave it should remove them.
However, I can’t seem to add them to the table in the first place. Any help would be really appreciated
Are you sure this is the full script? Make sure that there are not other factors that could break the code, or maybe the script being on the wrong place
It’s just a code segment for my full script. I’m sure there is something preventing it from working as you are saying. However, I’ll test it out in an empty script sometime soon😊
The full script is around 1.5k~ lines, so I’m not gonna post it here
table.remove expects an index, not a value to remove.
The correct code would’ve been:
game.Players.PlayerRemoving:Connect(function(plr)
if table.find(playing, plr.Name) then
table.remove(playing, table.find(playing, plr.Name))
warn('Player has been removed from Playing Table!')
else
warn('Player is leaving successfully! No table issues')
end
end)