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 5 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

01local brick = script.Parent
02 
03function onTouched(hit)
04    for i,player in ipairs(game.Players:GetPlayers()) do
05        if player.Character then
06            local stat = player:FindFirstChild("leaderstats")
07            if stat then
08                player.leaderstats.Money.Value = player.leaderstats.Money.Value +1
09                brick:Destroy()
10            end
11        end
12    end
13end
14 
15 
16brick.Touched:connect(onTouched)

btw sorry for possible confusion first question

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

1 answer

Log in to vote
0
Answered by
moo1210 587 Moderation Voter
5 years ago
Edited 5 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.

01game.Players.PlayerAdded:connect(function(player)
02    local stats = Instance.new("IntValue")
03    stats.Name = "leaderstats"
04 
05    local money = Instance.new("IntValue")
06    money.Name = "Money"
07 
08    stats.Parent = player
09    money.Parent = stats
10end)

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 — 5y
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 — 5y
Ad

Answer this question