When a player purchases the devprod, a part falls from the sky randomly

Hey so i want to make a script where if the player buys the devprod, a part falls from the sky randomly on the map which is a 200x200 (with Y = 20).

local mps = game:GetService("MarketplaceService")
local players = game:GetService("Players")

local devProductId = 1228235407


local function promptPurchase ()
	local player = players.LocalPlayer
	mps:PromptProductPurchase(player, devProductId)
end

script.Parent.MouseButton1Click:Connect(promptPurchase)


mps.PromptProductPurchaseFinished:Connect(function(userId, productId, isPurchased)
	if isPurchased then
		local Player = players:GetPlayerByUserId(userId)
		if Player then
			if productId == devProductId then
				local part = Instance.new("Part")
				local randomX = math.random()
				local randomY = math.random()
				local randomZ = math.random()
				part.Size = Vector3.new(4,1,2)
				part.Position = Vector3.new(randomX, randomY, randomZ)
				part.Parent = workspace
				
			end
		elseif not Player then
			return Enum.ProductPurchaseDecision.NotProcessedYet
		end
	end
end)

PromptProductPurchaseFinished is deprecated, you must use ProcessReceipt and in a server script

LocalScript:

local mps = game:GetService("MarketplaceService")
local player = game:GetService("Players").LocalPlayer

local devProductId = 1228235407
script.Parent.MouseButton1Click:Connect(function()
	mps:PromptProductPurchase(player, devProductId)
end)

Script:

local devProductId = 1228235407
game:GetService("MarketplaceService").ProcessReceipt = function(receiptInfo)
	local Player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
	if not Player or receiptInfo.ProductId ~= devProductId then
		warn("Invalid product or player")
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	
	local part = Instance.new("Part")
	local randomX = math.random()
	local randomY = math.random()
	local randomZ = math.random()
	part.Size = Vector3.new(4,1,2)
	part.Position = Vector3.new(randomX, randomY, randomZ)
	part.Parent = workspace

	return Enum.ProductPurchaseDecision.PurchaseGranted
end
1 Like