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

Adding leaderstats value script wrong?

Asked by
Ap_inity 112
8 years ago
Edited 8 years ago

So, i am trying to make a script that, once a player has a gamepass, it would give 50 money every minute.

Here's my script i've got so far..

01DataStore = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
02local plr = game.Players.LocalPlayer
03 
04game:GetService("MarketplaceService").ProcessReceipt = function(infoo)
05    local playerDPkey = infoo.PlayerId..":"..infoo.PurchaseId
06    if DataStore:GetAsync(playerDPkey) then
07    else
08        print(playerDPkey)
09        for i,v in pairs(game.Players:GetChildren()) do
10            if v.userId == infoo.PlayerId then
11                if infoo.ProductId == 667369456 then
12                    plr.leaderstats.Value = plr.leaderstats.Value + 50 -- Gives 50 money
13                    wait(70)
14                    repeat
15                        plr.leaderstats.Value = plr.leaderstats.Value + 50 -- Repeats
View all 22 lines...

It doesn't add the money to the player.

If you think anything's wrong, let me know with an answer or a comment. Thanks!

1 answer

Log in to vote
0
Answered by 8 years ago

You are trying to add value directly to the leaderstats value, which is incorrect.

I don't know the correct name of the value you want to change (whether it's Money, Cash, etc), so I'll just put a string variable for you to change at the top. All you need to do is add one more path into the adding value to make it add to the specific money value.

01local nameVal = "Money" -- change the name of this to whatever the actual name of the value is
02 
03DataStore = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
04local plr = game.Players.LocalPlayer
05 
06game:GetService("MarketplaceService").ProcessReceipt = function(infoo)
07    local playerDPkey = infoo.PlayerId..":"..infoo.PurchaseId
08    if DataStore:GetAsync(playerDPkey) then
09    else
10        print(playerDPkey)
11        for i,v in pairs(game.Players:GetChildren()) do
12            if v.userId == infoo.PlayerId then
13                if infoo.ProductId == 667369456 then
14                    plr.leaderstats[nameVal].Value = plr.leaderstats[nameVal].Value + 50
15                    wait(70)
View all 24 lines...
Ad

Answer this question