MarketPlaceService : give something to the player

Hello,

how can I give something to the player if he/she bought?

local plr = game:GetService("Players").LocalPlayer

local Market = game:GetService("MarketplaceService")

local devProduct = script.Parent.DevProduct

local function buy()

    Market:PromptProductPurchase(plr, devProduct.Value)

end

script.Parent.MouseButton1Click:Connect(function() buy() end)

script.Parent.ImageButton.MouseButton1Click:Connect(function() buy() end)
-- \\ Server script //

function GiveItem(RecieptInfo)
	local Player = game.Players:GetPlayerByUserId(RecieptInfo.PlayerId)
	if not Player then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	if Player then
		print("Player is still in game..")
		if RecieptInfo.ProductId == YourProductId then
			print("Player has bought a devproduct!")
			return  Enum.ProductPurchaseDecision.PurchaseGranted
	   end
	end
end

game:GetService("MarketPlaceService").ProcessReciept = GiveItem

Put this in a completely new script (Server Script)

So I have to use remote event?

No. Just add this script in a completely new server script.

Yeah but I am using a localscript for buttons so I have to do with a remote event.

Oh changed my script, and no need for remote events…? This happens right after a purchase is bought. Use my changed script. Don’t worry about any remote events.

1 Like

Ah I thought I have to use remote event to call the function or something like it.

Thank for your help, have a good day :slight_smile: !

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.