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

Trying to set up a DevProduct, can't work out why it won't work, any pointers?

The script is related to a GUI Button, it opens up DevProduct Prompt and allows a purchase but dosent actually add the money.

local button = script.Parent
local mpService = game:GetService('MarketplaceService')

button.MouseButton1Down:connect(function()
	mpService:PromptProductPurchase(game.Players.LocalPlayer, 217674504 )
end)

function mpService.ProcessReceipt(receiptInfo)
	local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
	if receiptInfo.ProductId == 217674504  then
		player.leaderstats.Shillings.Value = player.leaderstats.Shillings.Value + 100
		return Enum.ProductPurchaseDecision.PurchaseGranted
	end
end


Cheers for the Help

1 answer

✓ Accepted answer

You can't use MarketplaceService on a LocalScript, or in a player since some weird things may happen. ProcessReceipt can only be used in one script, or else it will glitch out. It's like a bunch of players respawning and it keeps on triggering "ProcessReceipt" since it's in a GUI element.

So, you need to make it separate scripts, the button script on the button and the one that runs ProcessReceipt somewhere else, that will only make it run once.

So, here's a step by step process on how to fix it:

  1. Insert a LocalScript in the button
  2. Put this code in the button:
local button = script.Parent
local mpService = game:GetService('MarketplaceService')

button.MouseButton1Down:connect(function()
    mpService:PromptProductPurchase(game.Players.LocalPlayer, 217674504 )
end)

3 & 4: Insert a Script in "ServerScriptService" & Put this code in the Script:

local mpService = game:GetService('MarketplaceService')
function mpService.ProcessReceipt(receiptInfo)
    local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
    if receiptInfo.ProductId == 217674504  then
        player.leaderstats.Shillings.Value = player.leaderstats.Shillings.Value + 100
        return Enum.ProductPurchaseDecision.PurchaseGranted
    end
end

And you're done! :)

This has been tested, and it works. DO NOT keep on duplicating the script in "ServerScriptService" to put more codes in, or else it will glitch.

1 comment

0

Thats great thank you, i'll be adding you name to the credits for the scripting help, cheers mate.

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