Hello
I need help checking if a player is dead and removing him from the table
Script:
local TableArena = {}
local TablePlayers = {}
local Events = require(script.Events)
function PlayerAdded(Player)
table.insert(TablePlayers, Player)
print(TablePlayers)
end
game.Players.PlayerAdded:Connect(PlayerAdded)
while true do
repeat
wait(1)
until table.maxn(TablePlayers) >=2
wait(5)
Events.GameStart(TablePlayers, TableArena)
repeat
Events.RandomEvent(TableArena)
wait(20)
until table.maxn(TableArena) == 1
end
Module Script:
local Events = {}
function Events.GameStart(TablePlayer, TableArena)
for _,v in pairs(TablePlayer) do
table.insert(TableArena, v)
v.Character.HumanoidRootPart.CFrame = workspace.Arena.Tp.CFrame
end
end
return Events
I want to remove a player from the table if he dies if he is in the table “TableArena”
All the ways I did didn’t work
local TableArena = {}
local TablePlayers = {}
local Events = require(script.Events)
function PlayerAdded(Player)
table.insert(TablePlayers, Player)
print(TablePlayers)
end
game.Players.PlayerAdded:Connect(PlayerAdded)
while true do
repeat
wait(1)
until table.maxn(TablePlayers) >= 2
wait(5)
Events.GameStart(TablePlayers, TableArena)
for _, player in TableArena do --loop over all the players in TableArena
local humanoid = player.Character:FindFirstChild("Humanoid") --get the humanoid
humanoid.Died:Once(function() --when player dies execute this function
table.remove(TableArena, table.find(TableArena, player)) --find the position of the dead player and remove it from the the TableArena table.
end)
end
repeat
Events.RandomEvent(TableArena)
wait(20)
until table.maxn(TableArena) == 1
end