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:
1 | --I want this to check if the redTeam is dead, or if both the green AND blue team are BOTH dead. |
2 | if redTeam = = "" then |
3 | --code |
4 | elseif greenTeam = = "" and blueteam = = "" then |
5 | --code |
6 | end |
And my second question, how would I remove a player from a table if he dies? My attempted code:
01 | function playerDied(humanoid) |
02 | local player = humanoid.Parent.Parent |
03 | if redTeam [ player ] then |
04 | table.remove(redTeam,player) |
05 | elseif greenTeam [ player ] then |
06 | table.remove(greenTeam,player) |
07 | elseif blueTeam [ player ] then |
08 | table.remove(blueTeam,player) |
09 | else |
10 | end |
11 | end |
Also, would the following efficiently call playerDied?
1 | while true do |
2 | for i,v in pairs (game.Players:GetChildren()) do |
3 | v.Character:WaitForChild( "Humanoid" ).Died:connect(playerDied) |
4 | end |
5 | wait() |
6 | end |
First question:
1 | for i = 1 ,#RedTeam do |
2 | print (RedTeam [ i ] .Name) -- will print the name of everyone in this table. |
3 | end |
Second question:
01 | for a,b in pairs (TableName) |
02 | b.Character.Humanoid.Died:connect( function (playerDied) |
03 | end |
04 |
05 | function playerDied(p) |
06 | for a,b in pairs (TableName) do |
07 | if p.Name = = b.Name then |
08 | table.remove(TableName,a) |
09 | end |
10 | end |