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

How to make developer product work until player leaves the server?

Asked by 7 years ago

I want to edit my dev. product script to give the player extra health until he leaves the server. How do I go about doing this?

The button script to prompt the purchase works fine. It is only this portion that I need to edit:

local MarketplaceService = game:GetService("MarketplaceService")
local HealthID, PointsID = 89333927
local PurchaseHistory = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")

MarketplaceService.ProcessReceipt = function(receiptInfo) 

    for i, player in ipairs(game.Players:GetChildren()) do
        if player.userId == receiptInfo.PlayerId then
            if receiptInfo.ProductId == HealthID then
                player.Character.Humanoid.MaxHealth = player.Character.Humanoid.MaxHealth + 50
                player.Character.Humanoid.Health = player.Character.Humanoid.Health + 50
            end
        end 
    end
    local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_purchase_" .. receiptInfo.PurchaseId
    PurchaseHistory:IncrementAsync(playerProductKey, 1) 
    return Enum.ProductPurchaseDecision.PurchaseGranted     
end

Right now it only gives the said purchaser + 50 health until he or she dies. Then it resets back to 100 MaxHealth and 100 Health.

1 answer

Log in to vote
1
Answered by
Asceylos 562 Moderation Voter
7 years ago
Edited 7 years ago

By using the event CharacterAdded.

local MarketplaceService = game:GetService("MarketplaceService")
local HealthID, PointsID = 89333927
local PurchaseHistory = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")

MarketplaceService.ProcessReceipt = function(receiptInfo) 

    for i, player in ipairs(game.Players:GetChildren()) do
        if player.userId == receiptInfo.PlayerId then
            if receiptInfo.ProductId == HealthID then
                 player.CharacterAdded:connect(function()
                player.Character.Humanoid.MaxHealth = player.Character.Humanoid.MaxHealth + 50
                player.Character.Humanoid.Health = player.Character.Humanoid.Health + 50
                 end)
            end
        end 
    end
    local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_purchase_" .. receiptInfo.PurchaseId
    PurchaseHistory:IncrementAsync(playerProductKey, 1) 
    return Enum.ProductPurchaseDecision.PurchaseGranted     
end
0
Thank you. killerthedemon 14 — 7y
0
Feel free to accept my answer if this helped you. Asceylos 562 — 7y
0
Don't forget to also add it when they purchase it, so they aren't forced to reset for it to work. RubenKan 3615 — 7y
Ad

Answer this question