I was making a program that finds whenever there's 1 person left alive, so here's the script:
local AlivePlrs = {}
while #AlivePlrs ~= 1 do
wait()
for _, Char in pairs(game.Workspace:GetChildren()) do
wait()
if Char:IsA("Model") and Char:FindFirstChild("Humanoid") then -- Make sure it's a Character, not something else
local Humanoid = Char.Humanoid
table.insert(AlivePlrs, #AlivePlrs + 1, Char.Name)
Humanoid.Died:connect(function()
for Position, Plr in ipairs(AlivePlrs) do
wait()
if Plr == Char.Name then -- If they are in the table then...
table.remove(AlivePlrs, Position) -- Position is an iterator which gives a number, in this case we can use that number to find where their name is in this table and remove it
end
end
end)
end
end
wait()
end
print(AlivePlrs[1].Name)
game.Workspace.Win:Fire(AlivePlrs[1])
There's an error message that AlivePlrs[1] is nil.

2 comments
Are you sure you put any values inside the AlivePlrs array, if you do can you please show the full code
This is the entire code, just runs until there's 1 player left