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 » Scripting Helpers
Home Search
 

Re: Table help

Previous Thread :: Next Thread 
Rasder is not online. Rasder
Joined: 21 Jun 2011
Total Posts: 88
23 Jan 2013 08:00 AM
Survivors = {}

game.Players.PlayerAdded:connect(function(Player)
~Player.CharacterAdded:connect(function(Character)
~~Character.Humanoid.Died:connect(function()
~~~if Survivors[Player.Name] then
~~~~Survivors[Player.Name] = nil---- i think the problem is in this line
~~~end
~~end)
~end)
end)

i have this script but when someone dies the table does not remove i think the problem is on the line with the message.or it can also be because the player adds to quicly to the survivors table
Report Abuse
Trioxide is not online. Trioxide
Joined: 29 Mar 2011
Total Posts: 32902
23 Jan 2013 08:04 AM
[ Content Deleted ]
Report Abuse
Rasder is not online. Rasder
Joined: 21 Jun 2011
Total Posts: 88
23 Jan 2013 08:05 AM
It still doesnt work with table remove.Should i add a wait or someothing like that?
Report Abuse
ellosss is not online. ellosss
Joined: 15 Mar 2009
Total Posts: 7030
23 Jan 2013 08:11 AM
Survivors = {}

Game.Players.PlayerAdded:connect(
function(Player)
Player.CharacterAdded:connect(
function(Character)
repeat wait() until Character:FindFirstChild("Humanoid") -- Give game time to find Humanoid.
Character.Humanoid.Died:connect(
function()
if Survivors[Player.Name] then
table.remove(Survivors,Player.Name)
end
end)
end)
end)
Report Abuse
Rasder is not online. Rasder
Joined: 21 Jun 2011
Total Posts: 88
23 Jan 2013 12:26 PM
It still does not remove a player from the table when he dies any other ideas ?
Report Abuse
noliCAIKS is not online. noliCAIKS
Joined: 08 Mar 2010
Total Posts: 917
23 Jan 2013 01:25 PM
`table.remove' only works with numeric indices.
Perhaps the humanoid isn't loaded yet. Try this:

game.Players.PlayerAdded:connect(function(Player)
   Player.CharacterAdded:connect(function(Character)
      local Humanoid = Character:FindFirstChild("Humanoid")
      while not Humanoid or not Humanoid:IsA("Humanoid") do
         Humanoid = Character.ChildAdded:wait()
      end
      Humanoid.Died:connect(function()
         if Survivors[Player.Name] then
            Survivors[Player.Name] = nil
         end
      end)
   end)
end)
Report Abuse
Rasder is not online. Rasder
Joined: 21 Jun 2011
Total Posts: 88
23 Jan 2013 01:46 PM
it doesnt work.Also there is no output error may be i am putting this part on the wrong order?.Well first at the start of a round there is this text

Survivors = {}

game.Players.PlayerAdded:connect(function(Player)
Player.CharacterAdded:connect(function(Character)
local Humanoid = Character:FindFirstChild("Humanoid")
while not Humanoid or not Humanoid:IsA("Humanoid") do
Humanoid = Character.ChildAdded:wait()
end
Humanoid.Died:connect(function()
if Survivors[Player.Name] then
Survivors[Player.Name] = nil
end
end)
end)
end)

Before the script teleport the players to the map i insert this

for _, Player in pairs(game.Players:GetPlayers()) do
table.insert(Survivors, Player.Name)
end
then to determinate if there is more than 1 surviver i use this
while #Survivors ~= 1 do
wait(5)

print(#Survivors)
end
for i = 1, #Survivors do
m.Parent = game.Workspace
m.Text = "The Winner of the round is "..Survivors[i]
wait(5)
end

and finnaly ehrn the round ends i clear the survivors list by this
Survivors = {}

Well its anything wrong on what i wrote and the propuse.Thanks
Report Abuse
Rasder is not online. Rasder
Joined: 21 Jun 2011
Total Posts: 88
23 Jan 2013 02:05 PM
Any ideas or help?
Report Abuse
mexati is not online. mexati
Joined: 02 Aug 2009
Total Posts: 318
23 Jan 2013 02:27 PM
Im not sure if Survivors[Instance] should work since the table is sopposed to store the instance at a given number : Survivors[Number of the instance]

if survivors[Player.Name] then
is not a condition and there for I dont think it works.
Report Abuse
Rasder is not online. Rasder
Joined: 21 Jun 2011
Total Posts: 88
23 Jan 2013 02:33 PM
So how i can fix it could you rewrite or fix that part for me?
Thanks
Report Abuse
mexati is not online. mexati
Joined: 02 Aug 2009
Total Posts: 318
23 Jan 2013 02:39 PM
if Survivors[num].Player ~= nil then
Would be a working condition but, I'm not sure that I know the best way to find a registration number of the aimed Survivor. I recommend trying to find a useful function at the roblox.wiki.
Report Abuse
builderman1171 is not online. builderman1171
Joined: 27 Mar 2010
Total Posts: 1595
23 Jan 2013 03:01 PM
Survivors={}
game.Players.PlayerAdded:connect(function(Player)
table.insert(Survivors,Player.Name)
Player.CharacterAdded:connect(function()
repeat wait() until Player.Character:findFirstChild("Humanoid")
Player.Character.Humanoid.Died:connect(function()
table.remove(Survivors,Player.Name)
end)
end)
end)
Report Abuse
noliCAIKS is not online. noliCAIKS
Joined: 08 Mar 2010
Total Posts: 917
23 Jan 2013 03:35 PM
`table.insert' and `table.remove' always use numeric indices, so table.remove(Surivors, Player.Name) can't possibly work.
table.insert(Surivors, Player.Name) is the same as Survivors[#Survivors + 1] = Player.Name, so obviously Survivors[Player.Name] = nil won't remove it from the table.
I would replace table.insert(Surivors, Player.Name) by Survivors[Player.Name] = true, but that makes #Survivors invalid which might be complicated for you to fix.
Therefore, your best bet is to replace Survivors[Player.Name] = nil by the following:
for index, name in ipairs(Survivors) do
~if name == Player.Name then
~~table.remove(Survivors, index)
~~break
~end
end
Report Abuse
noliCAIKS is not online. noliCAIKS
Joined: 08 Mar 2010
Total Posts: 917
23 Jan 2013 03:38 PM
If you are going to use my solution, don't forget to remove the `if Survivors[Player.Name] then' part, as it's not valid.
Report Abuse
jelly134 is not online. jelly134
Joined: 25 Aug 2008
Total Posts: 1137
23 Jan 2013 04:17 PM
'if Survivors[Player.Name] then' is a perfectly valid condition. If there is nothing after the variable, like in this case, the condition runs if the variable is either TRUE or simply does not equal NIL. This condition checks if Survivors[Player.Name] has been assigned and does not equal nil, which to me seems like a perfectly good condition. The '~= nil' is not necessary, however, 'if Survivors[Player.Name] ~= nil then' is the EXACT same as the condition above.

- Jelly134
Wiki Staff Profile: http://wiki.roblox.com/index.php/User:Jelly134
Report Abuse
noliCAIKS is not online. noliCAIKS
Joined: 08 Mar 2010
Total Posts: 917
24 Jan 2013 01:00 AM
The problem is that Survivors[Player.Name] is never assigned; Survivors[1] and Survivors[2] are (for example).
Report Abuse
Rasder is not online. Rasder
Joined: 21 Jun 2011
Total Posts: 88
24 Jan 2013 07:43 AM
Tank you very much guys
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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