Not sure how to fix this

Hey, so today I made a Buy Points GUI for my game, and I’m not sure how to achieve this concept:

The player buys the developer product, it gives them the amount of points, in this case, 2000 points.

Code:


script.Parent.MouseButton1Click:Connect(function()
	game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer,id)
	game:GetService("MarketplaceService"):PlayerOwnsAsset(id) = true then
	game.Players.LocalPlayer.leaderstats.Points.Value + 2000
end)

Can someone please fix this?
1 Like

You will need to create a PurchaseHandler for this.

See: MarketplaceService.ProcessReceipt (roblox.com)

1 Like

like mentioed above by Andrew_Starr, you need to create Purchase Handler, Here’s just an example how you need to do it. :slight_smile:

Follow this two links for more Info: Developer Products | Documentation - Roblox Creator Hub
MarketplaceService | Documentation - Roblox Creator Hub

-- SERVER SIDE SCRIPT --
   
    local MarketplaceService = game:GetService("MarketplaceService")
    local DataStoreService = game:GetService("DataStoreService")

    local ServerStorage = game:GetService("ServerStorage")

    local PreviousPurchases = DataStoreService:GetDataStore("PreviousPurchases1")

    MarketplaceService.ProcessReceipt = function(receipt)

    	local ID = receipt.PlayerId.."-"..receipt.PurchaseId

    	local success = nil

    	pcall(function()
    		success = PreviousPurchases:GetAsync(ID)
    	end)

    	if success then -- Has it already been bought ?
    		-- Purchase has already been done
    		return Enum.ProductPurchaseDecision.PurchaseGranted
    	end

    	local player = game.Players:GetPlayerByUserId(receipt.PlayerId)

    	if not player then
    		-- Left, disconnected
    		return Enum.ProductPurchaseDecision.NotProcessedYet -- We're going to give their rewards next time they join / next time fired
    	else

    		if receipt.ProductId == IDHere then
	           player.leaderstats.Points.Value + 2000
    		end
    		pcall(function()
    			PreviousPurchases:SetAsync(ID,true)
    		end)

    		return Enum.ProductPurchaseDecision.PurchaseGranted

    	end
    end

-- LOCAL SCRIPT --

local MarketplaceService = game:GetService("MarketplaceService")

script.Parent.MouseButton1Click:Connect(function()
	MarketplaceService:PromptProductPurchase(Player, IDHere)
end)