Right now I have a dev. product set up to give a player +50 health upon purchasing a developer product. This works and all, and even continues working after the player resets.
However it lasts forever. I.e the player can leave and rejoin and still have 150 MaxHealth and 150 Health. I only want it to last until the player leaves the server or rejoins.
This is the script I have
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
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
I know it has something to do with the CharacterAdded. I don't know how to get around this. Help would be appreciated!

1 comment
Thank you for your help again.