I'm a bit new to Tables, and utilizing them. I've got a few questions. First of all, I want my script to check if a table is empty or not. Here is the code I have so far:
--I want this to check if the redTeam is dead, or if both the green AND blue team are BOTH dead. if redTeam == "" then --code elseif greenTeam == "" and blueteam == "" then --code end
And my second question, how would I remove a player from a table if he dies? My attempted code:
function playerDied(humanoid) local player = humanoid.Parent.Parent if redTeam[player] then table.remove(redTeam,player) elseif greenTeam[player] then table.remove(greenTeam,player) elseif blueTeam[player] then table.remove(blueTeam,player) else end end
Also, would the following efficiently call playerDied?
while true do for i,v in pairs(game.Players:GetChildren()) do v.Character:WaitForChild("Humanoid").Died:connect(playerDied) end wait() end
First question:
for i = 1,#RedTeam do print(RedTeam[i].Name) -- will print the name of everyone in this table. end
Second question:
for a,b in pairs(TableName) b.Character.Humanoid.Died:connect(function(playerDied) end function playerDied(p) for a,b in pairs(TableName) do if p.Name == b.Name then table.remove(TableName,a) end end