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

Developer Product won't add 10 health when purchased?


a = player.Character.Humanoid.MaxHealth 

local MarketplaceService = Game:GetService("MarketplaceService")
local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
local productId = 19697165 -- Put id here for it


MarketplaceService.ProcessReceipt = function(receiptInfo) 

	
	for i, player in ipairs(game.Players:GetChildren()) do
		if player.userId == receiptInfo.PlayerId then
			
			
			
			if receiptInfo.ProductId == productId then
				
				
				player.Character.Humanoid.MaxHealth = a + 10 -- Where the health is added 
				
				
				game.Workspace.DisplayScreen.SurfaceGui.TextBox.Text = player.Name .. " has purchased a healing Upgrade." -- Tells the player about the purchase
			end
		end
	end	
	
	
	local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_purchase_" .. receiptInfo.PurchaseId
	ds:IncrementAsync(playerProductKey, 1)	
	
	
	return Enum.ProductPurchaseDecision.PurchaseGranted		
end
	

Have I done this completely wrong? Because it is not working and remember I am only a beginner. I wanted to make this into a GUI too if anyone has experience on that.

Thanks

1 comment

0

WOuld I be able to transform this into a GUI too?

1 answer

✓ Accepted answer

Player is not defined when you are setting the variable, therefore the script errors at the very beginning.

local MarketplaceService = Game:GetService("MarketplaceService")
local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
local productId = 19697165 -- Put id here for it


MarketplaceService.ProcessReceipt = function(receiptInfo) 


    for i, player in ipairs(game.Players:GetChildren()) do
        if player.userId == receiptInfo.PlayerId then



            if receiptInfo.ProductId == productId then
		local a = player.Character.Humanoid.MaxHealth


                player.Character.Humanoid.MaxHealth = a + 10 -- Where the health is added 


                game.Workspace.DisplayScreen.SurfaceGui.TextBox.Text = player.Name .. " has purchased a healing Upgrade." -- Tells the player about the purchase
            end
        end
    end 


    local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_purchase_" .. receiptInfo.PurchaseId
    ds:IncrementAsync(playerProductKey, 1)  


    return Enum.ProductPurchaseDecision.PurchaseGranted     
end

1 comment

0

Didn't change anything, but thanks for the help anyway!

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