Like when a player is added or respawned?
✓ ANSWER ACCEPTED
What function would be best to add a player in?
1 answer
✓ Accepted answer
The events .PlayerAdded and .PlayerRemoving are used like this:
players = {}
function RemoveFromTable(thetable, toberemoved) -- That's a function I made due to no such function existing.
if thetable == nil then
error("ERROR | FIRST ARGUMENT/TABLE IS NIL | FUNCTION: RemoveFromTable")
end
if thetable == nil then
error("ERROR | SECOND ARGUMENT/OBJECT IS NIL | FUNCTION: RemoveFromTable")
end
local istoberemovedintable = false
for _, yesorno in pairs(thetable) do
if yesorno == toberemoved then
istoberemovedintable = true
end
end
if istoberemovedintable == false then
error("ERROR | SECOND ARGUMENT/OBJECT IS NOT IN TABLE | FUNCTION: RemoveFromTable")
end
for i = 1/table.getn(thetable), table.getn(thetable) do
if thetable[i*table.getn(thetable)] == toberemoved then
table.remove(thetable, i*table.getn(thetable))
end
end
end
game.Players.PlayerAdded:connect(function(plr)
table.insert(players, plr)
end)
game.Players.PlayerAdded:connect(function(plr)
RemoveFromTable(players, plr)
end)
But an easier way would be to just use the :GetPlayers() function. Like this:
players = game.Players:GetPlayers()
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
Wow, that's a lot for playersadded, looks a bit too much, I'll try using :GetPlayers(), thanks!
Also is it possible to get the character like player.Character and get the PlayerGui like player.PlayerGui?
Yes.