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 7 years ago
Edited 7 years ago
function waitforwin()
local juggy = game.Players:WaitForChild(workspace.Survivors.Juggernaut.Value)
local juggychar = juggy.Character
local plrs = game.Players:GetPlayers()
local players = {}
table.insert(players, plrs.Name)
for i,v in pairs (players) do 
    if v == juggy.Name then
        table.remove(players, i)
    end
end
juggychar.Humanoid.Died():connect(function()
    print ("players win")
end)
for i, player in pairs (plrs) do
    local chars = player.Character
chars.Humanoid.Died():connect(function()
for i,v in pairs (players) do
if v == plrs.Name then
    table.remove(players, i)
    for i, numofplayers in pairs (players) do
    if i > 1 then
    print (juggy.." won")
    end
end
end
end
end)
end
end

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 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

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

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

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

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

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:

for i, player in pairs (plrs) do
    local chars = player.Character
    chars.Humanoid.Died:connect(function()
        for i,v in pairs (players) do
            if v == player.Name
                table.remove(players, i)
                if #players < 1 then
                    print (juggy.." won")
                end
            end
        end
    end)
end
Ad

Answer this question