Block not spawning

I want a block to spawn whenever someone buys a dev product. However, the block is not spawning when I buy the dev product. I have tried to add prints into the function, but they are not running either. Here is my code in a ProximityPrompt in a part in the workspace.

local MPS = game:GetService("MarketplaceService")

local productID = 2679561268

local ProxPrompt = script.Parent


ProxPrompt.Triggered:Connect(function(plr)
	MPS:PromptProductPurchase(plr, productID)
	MPS.PromptPurchaseFinished:Connect(function(plr, productID, isPurchased)
		if isPurchased == true then
			print(plr.."has purchased a block!")
			local newBlock = Instance.new("Part")
			newBlock.Parent = workspace
			newBlock.CFrame = Vector3.new(80, 80, 0)
			newBlock.Color = Color3.new(math.random(0, 255), math.random(0, 255), math.random(0, 255))
		else	
			print(plr.."canceled the purchase.")
		end
	end)
end)
1 Like

I believe that you can only use the function PromptPurchaseFinish on server side

Try this:

local MPS = game:GetService("MarketplaceService")

local productID = 2679561268
local ProxPrompt = script.Parent

ProxPrompt.Triggered:Connect(function(plr)
    MPS:PromptProductPurchase(plr, productID)
end)

MPS.PromptPurchaseFinished:Connect(function(player, purchasedProductID, isPurchased)
    if purchasedProductID == productID and isPurchased then
        print(player.Name .. " has purchased a block!")
        
        local newBlock = Instance.new("Part")
        newBlock.Size = Vector3.new(4, 4, 4) -- Set size for clarity
        newBlock.Parent = workspace
        newBlock.CFrame = CFrame.new(80, 80, 0)
        newBlock.Color = Color3.new(
            math.random(), -- Normalize RGB values between 0 and 1
            math.random(),
            math.random()
        )
    else
        print(player.Name .. " canceled the purchase.")
    end
end)

Let me know if this works or if you need further help!

The script is a serverscript inside of the prompt

1 Like

Doesn’t seem to be working, same result as the first script.