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

How to update leaderboard lives after developer purchase?

Asked by 7 years ago

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

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

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
0
I added what you posted but it's still not adjusting the Souls/Lives SocialENTRcoRSE 21 — 7y
0
I fixed the issue thank you! SocialENTRcoRSE 21 — 7y
0
it was the local mpService = game.getService("MarketplaceService") having a . between game and get service instead of a : SocialENTRcoRSE 21 — 7y
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! SocialENTRcoRSE 21 — 7y
Ad

Answer this question