01 | function waitforwin() |
02 | local juggy = game.Players:WaitForChild(workspace.Survivors.Juggernaut.Value) |
03 | local juggychar = juggy.Character |
04 | local plrs = game.Players:GetPlayers() |
05 | local players = { } |
06 | table.insert(players, plrs.Name) |
07 | for i,v in pairs (players) do |
08 | if v = = juggy.Name then |
09 | table.remove(players, i) |
10 | end |
11 | end |
12 | juggychar.Humanoid.Died():connect( function () |
13 | print ( "players win" ) |
14 | end ) |
15 | for i, player in pairs (plrs) do |
It was calling Died() a userdata value and printed an error then i removed () from Died() and it didnt say that the player died.. this is confusing me...
Assuming that line 2 is correct, the first problem is with this:
1 | local plrs = game.Players:GetPlayers() |
2 | local players = { } |
3 | table.insert(players, plrs.Name) |
GetPlayers
returns a table of all players in the game, however you are trying to find the Name
property of the table. You need to iterate through the table and add the players' names like this:
1 | local plrs = game.Players:GetPlayers() |
2 | local players = { } |
3 | for i, v in ipairs (plrs) do |
4 | table.insert(players, v.Name) |
5 | end |
The next problem is with line 12. You need to leave out the () when connecting functions to events:
1 | juggychar.Humanoid.Died:connect( function () |
The for loop after that does not look like it does what you want it to do. Making several assumptions, this would be a corrected version:
01 | for i, player in pairs (plrs) do |
02 | local chars = player.Character |
03 | chars.Humanoid.Died:connect( function () |
04 | for i,v in pairs (players) do |
05 | if v = = player.Name |
06 | table.remove(players, i) |
07 | if #players < 1 then |
08 | print (juggy.. " won" ) |
09 | end |
10 | end |
11 | end |
12 | end ) |
13 | end |