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

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

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

✓ Accepted answer

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

3 comments

0

Thank you.

0

Feel free to accept my answer if this helped you.

0

Don't forget to also add it when they purchase it, so they aren't forced to reset for it to work.

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