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
|
  |
| Joined: 29 Mar 2011 |
| Total Posts: 32902 |
|
| |
|
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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 21 Jun 2011 |
| Total Posts: 88 |
|
| |
|
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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 21 Jun 2011 |
| Total Posts: 88 |
|
| |
|