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
7 years ago
Edited 7 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..

DataStore = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
local plr = game.Players.LocalPlayer

game:GetService("MarketplaceService").ProcessReceipt = function(infoo)
    local playerDPkey = infoo.PlayerId..":"..infoo.PurchaseId
    if DataStore:GetAsync(playerDPkey) then
    else
        print(playerDPkey)
        for i,v in pairs(game.Players:GetChildren()) do
            if v.userId == infoo.PlayerId then
                if infoo.ProductId == 667369456 then
                    plr.leaderstats.Value = plr.leaderstats.Value + 50 -- Gives 50 money
                    wait(70)
                    repeat
                        plr.leaderstats.Value = plr.leaderstats.Value + 50 -- Repeats
                    until
                    game.Players.LocalPlayer:ChildRemoved()
                end
            end
        end
    end         
end

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

local nameVal = "Money" -- change the name of this to whatever the actual name of the value is

DataStore = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
local plr = game.Players.LocalPlayer

game:GetService("MarketplaceService").ProcessReceipt = function(infoo)
    local playerDPkey = infoo.PlayerId..":"..infoo.PurchaseId
    if DataStore:GetAsync(playerDPkey) then
    else
        print(playerDPkey)
        for i,v in pairs(game.Players:GetChildren()) do
            if v.userId == infoo.PlayerId then
                if infoo.ProductId == 667369456 then
                    plr.leaderstats[nameVal].Value = plr.leaderstats[nameVal].Value + 50 
                    wait(70)
                    repeat
                        plr.leaderstats[nameVal].Value = plr.leaderstats[nameVal].Value + 50
                    until
                    game.Players.LocalPlayer:ChildRemoved()
                end
            end
        end
    end         
end
Ad

Answer this question