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

Developer product won't work?

There is errors when i'm trying to click the developer product.

Error: 10:02:24.571 - Players.inpu_ts.PlayerGui.ScreenGui.Frame.TextButton.LocalScript:6: attempt to index local 'purchase' (a nil value)

Script:

local id = 332605014
local players = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	local purchase = game:GetService("MarketplaceService"):PromptProductPurchase(players, id)
			purchase.players.leaderstats.Money.Value = players.leaderstats.Money.Value + 2
	end)

1 comment

0

You're doing it wrong. Check this wiki page: http://robloxdev.com/articles/Developer-Products-In-Game-Purchases

1 answer

###PromptProductPurchase returns void. You'll have to check if the player purchased it with PromptPurchaseFinished. You're also awarding things on the client, which is bad because they can reward themselves so much more. This is your new script:

local id = 332605014 
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
    game:GetService("MarketplaceService"):PromptProductPurchase(player, id)
end)

###Server script, place in ServerScriptService

local MPS = game:GetService("MarketplaceService")

MPS.PromptPurchaseFinished:Connect(function(plr,id,bought) -- listens for prompt finish
    if id == 332605014 and bought then -- if they BOUGHT and not cancelled, and it's the id then
        plr.leaderstats.Money.Value = plr.leaderstats.Money.Value + 2 -- awarding on the server 
    end
end)

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