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

Some Spectating Issue?

Asked by 9 years ago

The previous function doesn't work, but the next function does. Once a player dies, most of this stop functioning correctly without errors. This spectate is suppose to view online "Alive" players.

PreviousSpectator.MouseButton1Down:connect(function()
    local ActivePlayersTable = {}
    local Amount = Gather()
    for _, Player in pairs(game.Players:GetPlayers()) do
        if Player:FindFirstChild("Playing") and Player.Playing.Value == true then
            table.insert(ActivePlayersTable, Player)
        end
    end
    if not pcall(function()
        if ActivePlayersTable[1] and ActivePlayersTable[1].Character then
            Camera.CameraSubject = ActivePlayersTable[Amount-1].Character:FindFirstChild("Humanoid")
            SpectateName.Text = ActivePlayersTable[Amount-1].Name
        end
    end) then
    if ActivePlayersTable[1] and ActivePlayersTable[1].Character then
        Camera.CameraSubject = ActivePlayersTable[#ActivePlayersTable].Character:FindFirstChild("Humanoid")
        SpectateName.Text = ActivePlayersTable[#ActivePlayersTable].Name
    end
    end
    pcall(function()
        SpectateName.Text = game.Players:GetPlayerFromCharacter(Camera.CameraSubject.Parent).Name
    end)
end)

NextSpectator.MouseButton1Down:connect(function()
    local ActivePlayersTable = {}
    local Amount = Gather()
    for _, Player in pairs(game.Players:GetPlayers()) do
        if Player:FindFirstChild("Playing") and Player.Playing.Value == true then
            table.insert(ActivePlayersTable, Player)
        end
    end
    if not pcall(function()
        if ActivePlayersTable[1] and ActivePlayersTable[1].Character then
            Camera.CameraSubject = ActivePlayersTable[Amount+1].Character:FindFirstChild("Humanoid")
            SpectateName.Text = ActivePlayersTable[Amount+1].Name
        end
    end) then
    if ActivePlayersTable[1] and ActivePlayersTable[1].Character then
        Camera.CameraSubject = ActivePlayersTable[1].Character:FindFirstChild("Humanoid")
        SpectateName.Text = ActivePlayersTable[1].Name
    end
    end
    pcall(function()
        SpectateName.Text = game.Players:GetPlayerFromCharacter(Camera.CameraSubject.Parent).Name
    end)
end)

Answer this question