Hello there! I am having an issue with removing table arrays after a player has died, and was curious to know if anybody has a solution to my code?
The issue occurs on the second round in of my game I am making, when it is supposed to check for the winner (there should only be one table array left). There are no errors, but when a player dies in the second round, no winner shows up and the game moves on because there is more than one array still left.
I have looked around to see if I could find a solution but for what I am trying to accomplish, I could not find an exact solution.
Server Script Code For Removing The Table:
local playersInGame = {
["In"] = {},
["Out"] = {},
}
Players.PlayerAdded:Connect(function(Player)
Char.Humanoid.Died:Connect(function()
for i,v in pairs(playersInGame["In"]) do
table.remove(playersInGame["In"], tonumber(table.find(playersInGame["In"], i)))
end
Player.Team = game.Teams.Out
table.insert(playersInGame["Out"], Player.Name)
wait(1)
Char.Humanoid.JumpPower = 0
end)
end)
Server Script Code For Adding The Table:
function SetupTeams()
for i,v in pairs(game.Players:GetPlayers()) do
v.Team = game.Teams.In
table.insert(playersInGame["In"],#playersInGame["In"]+1, v.Name)
print(unpack(playersInGame["In"])) --Was Just For Testing
end
end
Module Script To Check Table:
for i,v in pairs(playersInGame) do
print(#playersInGame["In"])
if #playersInGame["In"] == 1 then
print("tried to check winner")
local Winner = playersInGame["In"][1]
local WinnerChar = game.Players[Winner].Character or game.Players[Winner].CharacterAdded:wait()
print(unpack(playersInGame["In"]))
Status.Value = Winner.." won the game!"
wait(4)
Status.Value = ""
WinnerChar.Humanoid.JumpPower = 50
wait(0.1)
WinnerChar.Humanoid.Jump = true
wait(0.1)
WinnerChar.Humanoid.Health = 0
wait(0.1)
WinnerChar.Humanoid.JumpPower = 0
wait(0.5)
ResetChairs()
elseif #playersInGame["In"] > 1 then
for i,v in pairs(game.Players:GetPlayers()) do
local AllChars = v.Character or v.CharacterAdded:wait()
if v.Character.Humanoid.Sit == true then
v.Character.Humanoid.JumpPower = 50
wait(0.1)
v.Character.Humanoid.Jump = true
wait(0.1)
v.Character.Humanoid.JumpPower = 0
end
end
wait(.1)
ResetChairs()
SetupTeams()
TPandSetChairs()
StartRnd()
end
end
end
For anybody has any ideas or finds a fix, thank you so much!
Thatās what was printed after the second round.

The error on line 23 was just because I typed a print wrong.
