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

[ANSWERED] Attempt to index local 'third' (a nil value)?

Asked by 7 years ago
Edited 7 years ago

Output says "attempt to index local 'third' (a nil value)". How to make this work?

function leaderboard(first, second, third, fourth, fifth, sixth, seventh, eighth)
        return first.leaderstats.Score.Value > second.leaderstats.Score.Value > third.leaderstats.Score.Value > fourth.leaderstats.Score.Value > fifth.leaderstats.Score.Value > sixth.leaderstats.Score.Value > seventh.leaderstats.Score.Value > eighth.leaderstats.Score.Value
    end

    local players = {}
    for _, player in pairs(game.Players:GetPlayers()) do
        if player:FindFirstChild("leaderstats") and
            player.leaderstats:FindFirstChild("Score") then
            table.insert(players, player)
        end
    end

    table.sort(players, leaderboard)

    if players[1] then
        for _, player in pairs(game.Players:GetPlayers()) do
            player.PlayerGui.ScreenGui.Frame.Visible = true
            player.PlayerGui.ScreenGui.Frame.First.Text = "1. " .. players[1].Name
        end
        if players[2] then
            for _, player in pairs(game.Players:GetPlayers()) do
                player.PlayerGui.ScreenGui.Frame.Second.Text = "2. " .. players[2].Name
            end
            if players[3] then
                for _, player in pairs(game.Players:GetPlayers()) do
                    player.PlayerGui.ScreenGui.Frame.Third.Text = "3. " .. players[3].Name
                end
                if players[4] then
                    for _, player in pairs(game.Players:GetPlayers()) do
                        player.PlayerGui.ScreenGui.Frame.Fourth.Text = "4. " .. players[4].Name
-- And So on...
                    end
                end
            end
        end
    end

Thanks!

0
What line? OldPalHappy 1477 — 7y
0
the output displayed line 2. GatitosMansion 187 — 7y
0
You have completely mis-understood my answer. You need to learn functions and think before making random changes BlueTaslem 18071 — 7y
0
who is -repping every question EssentialRoll 30 — 7y

Answer this question