How can I add a player into a table when they join?

How would I be able to use this code to put the players name in the table and remove it when they leave

local Players = game:GetService("Players")

local Playerstable = {}

Players.PlayerAdded:Connect(function(player)
	-- put player into the players table
end)

Players.PlayerRemoving:Connect(function(player)
	-- remove player from the players table
end)

Any visualizations on what the table would look like once player has been added would be nice, thanks.

use table.insert, table.find, and table.remove

3 Likes

As @Bountiful_Update has already mentioned you would use table.insert to insert player into a table:

local Players = game:GetService("Players")

local Playerstable = {}

Players.PlayerAdded:Connect(function(player)
	table.insert(Playerstable, player)
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.