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.
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