generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: STILL need table help

Previous Thread :: Next Thread 
FactualTheory is not online. FactualTheory
Joined: 10 Sep 2013
Total Posts: 1365
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
FactualTheory is not online. FactualTheory
Joined: 10 Sep 2013
Total Posts: 1365
29 Jun 2015 05:29 PM
And when the game ends, they all leave
Report Abuse
Lucas1270z is not online. Lucas1270z
Joined: 27 Feb 2013
Total Posts: 439
29 Jun 2015 05:30 PM
table.remove

http://wiki.roblox.com/index.php?title=Function_dump/Table_manipulation
Report Abuse
phoenix53124 is not online. phoenix53124
Joined: 25 Feb 2009
Total Posts: 4889
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
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
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
nicemike40 is not online. nicemike40
Joined: 19 Dec 2008
Total Posts: 1814
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
nicemike40 is not online. nicemike40
Joined: 19 Dec 2008
Total Posts: 1814
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
CaptainSource is not online. CaptainSource
Joined: 08 Jun 2013
Total Posts: 848
29 Jun 2015 05:51 PM
:Q

I will use it.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image