Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 6 years ago

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

Log in to vote
0
Answered by
Rawblocky 217 Moderation Voter
6 years ago
Edited 6 years ago

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.

0
Thats great thank you, i'll be adding you name to the credits for the scripting help, cheers mate. Moo_Blinder 18 — 6y
Ad

Answer this question