Thank you but how do I do that?
removePlayer(player)
Just how you did it there
I redid the script to make it event based, and not use loops.
local Players = game:GetService("Players")
local PlayersTable = {}
Players.PlayerAdded:Connect(function(Player)
--round system
if #Players:GetPlayers() >= 4 then
for i = time1, 0, -1 do
status.Value = string.format('Starting in %s seconds', tostring(i))
wait(1)
end
for i, v in pairs(Players:GetPlayers()) do
table.insert(PlayersTable, #PlayersTable + 1, v)
end
startround()
for i = time2, 0, -1 do
status.Value = string.format('%s seconds left', tostring(i))
end
endRound()
else status.Value = '4 players needed to start a game'
end
--remove the player from the table if they die
Player.CharacterAdded:Connect(function(Character)
local Humanoid = Character:FindFirstChild("Humanoid")
if Humanoid then
Humanoid.Died:Connect(function()
local IndexInTable = table.find(PlayersTable, Player)
if IndexInTable then
table.remove(PlayersTable, IndexInTable)
end
end)
end
end)
end)
1 Like
Thank you! but what does ‘IndexInTable’ mean?
IndexInTable is a variable which returns the result of table.find(), the first argument is the table you will search at, and the second argument is the value that you will look for, in the table.
From what he used, it seems that you can also use indexes in the second argument of table.find.
Then, he checks if IndexInTable is not nil (If it didn’t find the player then it would be nil.), and then removes the player from the PlayersTable.
2 Likes