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

How to update leaderboard lives after developer purchase?

I have a developer purchase which activates and says successful but will not give the lives to the character for the purchase here is the two scripts im using for the leaderboard and the purchase.

Here is the Leaderboard Script

game.Players.PlayerAdded:Connect(function(plr)
    local Stats = Instance.new('Folder') 
    Stats.Name = 'leaderstats'
    Stats.Parent = plr
 
    local Lives = Instance.new('IntValue')
    Lives.Name = 'Souls'
    Lives.Value = 25
    Lives.Parent = Stats
 
    local Stage = Instance.new('IntValue')
    Stage.Name = 'Stage'
    Stage.Value = 0
    Stage.Parent = Stats
 
    local Timer = Instance.new('IntValue')
    Timer.Name = 'Time'
    Timer.Value = 0
    Timer.Parent = Stats
 
    plr.CharacterAdded:Connect(function(char)
        char.Humanoid.Died:Connect(function()
            Lives.Value = Lives.Value -1
			if Lives.Value <= 0 then
				char:SetPrimaryPartCFrame(workspace.Starter.CFrame)
				Stage.Value = 0
                Lives.Value = 25

					
			end
        end)
    end)
 
    while true do
        wait(1)
        Timer.Value = Timer.Value +1
    end
end)

Here is the Purchase Script

local Lives = game.Workspace.Leaderboard
local mpService = game.getService("MarketplaceService")

mpService.ProcessReceipt = function(purchaseInfo)
	local plr = game:GetService("Players"):GetPlayerByUserId(purchaseInfo.PlayerId)
	if purchaseInfo.ProductId == 55131820 then
		Lives.Value = Lives.Value +1
	end
	return Enum.ProductPurchaseDecision.PurchaseGranted
end

If anyone can help me figure out what is wrong it would be great. I've been stuck on this for awhile now and can't get past it. Thank you

1 answer

✓ Accepted answer

It looks like you are incrementing the wrong value.

In your leaderstats code, 'Lives' was actually named 'Souls' on line 7. So, on line 7 of the Purchase script, index the 'Souls' object from plr's leaderstats and you should be good.

local mpService = game.getService("MarketplaceService")

mpService.ProcessReceipt = function(purchaseInfo)
	local plr = game,Players:GetPlayerByUserId(purchaseInfo.PlayerId)
	if purchaseInfo.ProductId == 55131820 then
		--The value that will be incremented
		local Lives = plr.leaderstats.Souls;
		Lives.Value = Lives.Value +1
	end
	return Enum.ProductPurchaseDecision.PurchaseGranted
end

4 comments

0

I added what you posted but it's still not adjusting the Souls/Lives

0

I fixed the issue thank you!

0

it was the local mpService = game.getService("MarketplaceService") having a . between game and get service instead of a :

0

as well as the local plr = game.Players having a , between them instead of the . but I understand that is just accidental mistake you were a major help!

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