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

Developer product won't work?

Asked by 5 years ago

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)
0
You're doing it wrong. Check this wiki page: http://robloxdev.com/articles/Developer-Products-In-Game-Purchases Rare_tendo 3000 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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)
Ad

Answer this question