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

How do I change the roblox's leaderboards money count?

Asked by 4 years ago

I tried this in a script but I couldn't find a leaderboard object so I created one along with the code to add money but then when i tested it it didn't work can someone help

    local brick = script.Parent

    function onTouched(hit)
        for i,player in ipairs(game.Players:GetPlayers()) do
            if player.Character then
                local stat = player:FindFirstChild("leaderstats")
                if stat then
                    player.leaderstats.Money.Value = player.leaderstats.Money.Value +1
                    brick:Destroy()
                end
            end
        end
    end


    brick.Touched:connect(onTouched)

btw sorry for possible confusion first question

0
Where do you create the leader stats? ankurbohra 681 — 4y
0
I'm assuming he didn't create a leaderstat folder inside the player when they joined, otherwise this would've worked. killerbrenden 1537 — 4y

1 answer

Log in to vote
0
Answered by
moo1210 587 Moderation Voter
4 years ago
Edited 4 years ago

You can't just create a leaderstats object in studio, you need to bind with PlayerAdded and add a leaderstats value and then a money value under the leaderstats value. I'll provide an example below.

game.Players.PlayerAdded:connect(function(player)
    local stats = Instance.new("IntValue")
    stats.Name = "leaderstats"

    local money = Instance.new("IntValue")
    money.Name = "Money"

    stats.Parent = player
    money.Parent = stats
end)

This should not be in a brick that will be destroyed but in a script in workspace or ServerScriptService

0
This is creating a leaderstats, not changing a current one's value. -_- Slatryte 104 — 4y
1
Well, you have to create one first to be able to changing the current value. Because of what I'm seeing, he doesn't have a leaderstat and money value inside of the player, thus creating no leaderboard data. killerbrenden 1537 — 4y
Ad

Answer this question