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

Player With Most Points Not Announced After Game Finishes?

Asked by 6 years ago

Just a little edit to my old question, but after the game ends, the player's name won't show up. I don't know why, but I've gotten help from other helpful forum scripters, and used their edits, and it still hasn't worked for some reason. Here's the script.

To find the players with most points:

for i,v in pairs(game.Players:GetPlayers()) do
    function TopPlayers(team)
    local winners = {}
    local board = {}
    for _,v in next,team:GetPlayers() do
        local Points = v:WaitForChild("Points")
        board[#board+1] = {v,v.Points.Value}
    end
    table.sort(board, function(a,b) return a[2] > b[2] end)
    local highest = board[#board][2]
    for _,v in next,board do
        if v[2] == highest then
            winners[#winners] = v[1].Name
        end
    end
    return winners,highest
    end
end

Announces Player with most Points:

function EndRound()
local redWinners, redHighest = TopPlayers(game.Teams["CLE Cavaliers"])
local blueWinners, blueHighest = TopPlayers(game.Teams["GS Warriors"])
    for _,v in next,game.Players:GetPlayers() do
    local Points = v:WaitForChild("Points")
    v.Points.Value = 0
end
    display.Value = "Cavaliers MVP(s): "..table.concat(redWinners," , ").." with "..redHighest.." points!"
    wait(5)
    display.Value = "Warriors MVP(s): "..table.concat(blueWinners," , ").." with "..blueHighest.." points!"
    wait(5)
    display.Value = ""
end

At table.concat is where it usually messes up, I don't know why. It'll state the player's points, but it won't state the player's name.

Here's a picture:

Gyazo Screenshot

Hopefully we can fix this problem.

Thanks,

LukeGabrieI

1
Try indexing the table with '#winners + 1' instead. RayCurse 1518 — 6y
0
You saying that I should replace board with winners? Or specifically at what lines should I use that? I'm a little confused. LukeGabrieI 73 — 6y

Answer this question