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

How to add points to a player on a leaderboard?

Asked by 9 years ago
function InGroup(Player)
    return Player:IsInGroup("508662") or Player:GetRankInGroup(210856) >= 15
end

function onPlayerEntered(newPlayer)
    newPlayer.Chatted:connect(function(chatmsg)
        if InGroup(newPlayer) then
            if chatmsg:sub(1,12):lower() == ("Points Add: "):lower() then
                local player = game.Players:FindFirstChild(chatmsg:sub(13, chatmsg:len()-3))
                local comma = chatmsg:sub(chatmsg:len()-3, chatmsg:len()-1)
                local number = chatmsg:sub(chatmsg:len()-1, chatmsg:len()) 
                if player and comma == ", " then 
                    player.leaderstats["Training Points"].Value = player.leaderstats["Training Points"].Value + tonumber(number)
                end
            end
        end
    end)
end

game.Players.PlayerAdded:Connect(onPlayerEntered)

So far, this is the script that I have. I'm pretty sure that I did it correctly, but it doesn't work when I test it. The format for adding points (which are called Training Points) is [Points Add: (PlayerName), (Number)], and there has to be a comma and a space between the player's name and the number. Also, for the leaderboard, the values are already predetermined (the leaderboard works); it's just this script that I can't seem to get to work.

0
The last three characters for each command should be: ", #", with # being a number, and "," being a comma. Also, there should be a space between the number and comma.  poisonmonkey 30 — 9y

Answer this question