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

Why does this error "Argument 1 missing or nil"?

Asked by 8 years ago

Can anyone tell me what I'm doing wrong with this Spectate GUI as to why it's erroring on line 29? Error output is giving is Argument 1 missing or nil | Players.Player1.PlayerGui.ScreenGui.TextButton.LocalScript', Line 29.

Code(in a LocalScript):

-- Variables
local Player = game.Players.LocalPlayer
local Players = game.Players:GetPlayers()

local Alive = {}

-- Functions
local function GatherAlive()
    for i = 1,#Alive do
        if #Alive > 0 then
            print("Removed "..Alive[1])
            table.remove(Alive,1)
        end
    end
    for i = 1,#Players do
        if Players[i].TeamColor == "Bright red" or Players[i].TeamColor == "Bright blue" then
            table.insert(Alive,Players[i].Name)
            print("Added "..Alive[1])
        end
    end
end

script.Parent.MouseButton1Click:connect(function()
    GatherAlive()
    if #Alive > 0 then
        warn("0 alive")
        return false
    end
    game.Workspace.CurrentCamera.CameraSubject = game.Players:FindFirstChild(Alive[1]).Character.Humanoid
end)

Any help appreciated.

1 answer

Log in to vote
0
Answered by 8 years ago

Your if logic is wrong

script.Parent.MouseButton1Click:connect(function()
    GatherAlive()
    if #Alive == 0 then -- eq
        warn("0 alive")
        return false
    end
    game.Workspace.CurrentCamera.CameraSubject = game.Players:FindFirstChild(Alive[1]).Character.Humanoid
end)
Ad

Answer this question