Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Adding leaderstats value script wrong?

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

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.