Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

how would i determine if example 1 is still alive and and example 2 isnt? or the other way around

Asked by 8 years ago
Edited 8 years ago
01function waitforwin()
02local juggy = game.Players:WaitForChild(workspace.Survivors.Juggernaut.Value)
03local juggychar = juggy.Character
04local plrs = game.Players:GetPlayers()
05local players = {}
06table.insert(players, plrs.Name)
07for i,v in pairs (players) do
08    if v == juggy.Name then
09        table.remove(players, i)
10    end
11end
12juggychar.Humanoid.Died():connect(function()
13    print ("players win")
14end)
15for i, player in pairs (plrs) do
View all 30 lines...

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...

0
basically trying to make a juggernaut minigame sentry3 6 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

Assuming that line 2 is correct, the first problem is with this:

1local plrs = game.Players:GetPlayers()
2local players = {}
3table.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:

1local plrs = game.Players:GetPlayers()
2local players = {}
3for i, v in ipairs(plrs) do
4    table.insert(players, v.Name)
5end

The next problem is with line 12. You need to leave out the () when connecting functions to events:

1juggychar.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:

01for 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)
13end
Ad

Answer this question