|
| 29 Jun 2015 05:29 PM |
Thanks to dev tools, I got the first part of my problem.
local playing = {} for i, player in pairs (game.Players:GetChildren()) do if player and player.Character then local humanoid = player.Character:WaitForChild("Humanoid") if humanoid and humanoid.Health >=0 then table.insert(playing, player.Name) end end end
now for the next part, i have no clue how to do it. Could someone show me how to make it that when a person dies they leave the table?
Please help me!!! |
|
|
| Report Abuse |
|
|
|
| 29 Jun 2015 05:29 PM |
| And when the game ends, they all leave |
|
|
| Report Abuse |
|
|
|
| 29 Jun 2015 05:30 PM |
table.remove
http://wiki.roblox.com/index.php?title=Function_dump/Table_manipulation |
|
|
| Report Abuse |
|
|
|
| 29 Jun 2015 05:31 PM |
You could
A) Search the table for the name and use the index to remove it like so: table.remove(Table, 1)
B) Make it so that you can just go: MyTable.Player = nil by making your table like "MyTable.Player1=true" |
|
|
| Report Abuse |
|
|
|
| 29 Jun 2015 05:33 PM |
local playing = {} for i, player in pairs (game.Players:GetChildren()) do if player and player.Character then local humanoid = player.Character:WaitForChild("Humanoid") if humanoid and humanoid.Health >=0 then table.insert(playing, player.Name) humanoid.Died:connect(function() for i,v in pairs(playing) do if v == player.Name then table.remove(playing, i) break end end if #playing == 1 then Win(playing[1]) playing[1] = nil end end) end end end
Maybe? |
|
|
| Report Abuse |
|
|
|
| 29 Jun 2015 05:36 PM |
It would be easier for you, albeit barely less efficient, if you just created the table every time you needed it:
local function GetAlivePlayers() local alive = {} local players = game:GetService("Players"):GetPlayers() for i = 1, #players do local character = players[i].Character if character then local humanoid = character:FindFirstChild("Humanoid") if humanoid and humanoid.Health > 0 then alive[#alive + 1] = players[i] end end end return alive end
Then when you need the table, you just do
local alivePlayers = GetAlivePlayers()
~Upload code to codepad-dot-org with Lua syntax highlighting to preserve indentation and make it easier to read!~ |
|
|
| Report Abuse |
|
|
|
| 29 Jun 2015 05:47 PM |
If you want to be super fancy, you can do this to use the same table in memory:
local alivePlayers = setmetatable({}, { __call = function(self) local players = game:GetService("Players"):GetPlayers() local index = 0 for i = 1, #players do local character = players[i].Character if character then local humanoid = character:FindFirstChild("Humanoid") if humanoid and humanoid.Health > 0 then index = index + 1 self[index] = players[i] end end end for i = index + 1, #self do self[i] = nil end return self end })
Then do alivePlayers() to update the table, but still do stuff like
alivePlayers() for _, player in pairs(alivePlayers) do print(player.Name) end
~Upload code to codepad-dot-org with Lua syntax highlighting to preserve indentation and make it easier to read!~ |
|
|
| Report Abuse |
|
|
| |
|