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

Finding everyones points and if they have a certin amount of points game ends?

Asked by 8 years ago

Hi I was wonder if you can check all players points on the leaderboard, then if they have like 5 points the game ends. I am not requesting this, just can you help me?

2 answers

Log in to vote
1
Answered by
ImageLabel 1541 Moderation Voter
8 years ago
local highScore = 5 -- limit

-- create a function to return the "score" or value of the passed
-- argument/leaderstats
local function getScore(user, stat)
    if user and stat then
        -- if no empty parameters, proceed
        local stats = user:WaitForChild("leaderstats") 
        local score = stats:WaitForChild(stat)

        if score then
            -- return the value of the leaderstat
            -- if found
            return score.Value
        end
    end
end


-- game loop
local gameOver = false

while true do

    for _, player in next, game.Players:GetPlayers() do
        if getScore(player, "KOs") >= highScore then
            gameOver = true
        end
    end

    if gameOver then
        break
    else
        warn("game running")
    end
end
--
0
try it out ImageLabel 1541 — 8y
Ad
Log in to vote
0
Answered by 8 years ago
victorypoints = 5

for i,v in pairs(game.Players:GetChildren()) do
    if v.leaderstats.Points >= victorypoints then
        --GAME OVER CODE
    end
end

Answer this question