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

Developer Products Script Help?

Asked by 9 years ago
local buyButton = game.StarterGui.ShopMain.MoneyButton
local productId = 23342953

buyButton.MouseButton1Click:connect(function()
    game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer,                       productId)
end)

buyButton.MouseButton1Click:connect(function()
    local stats = user:findFirstChild("leaderstats")
    if stats ~= nil then
        local cash = stats:findFirstChild("Cash")
        cash.Value  = cash.Value +3000
end

--Please help me, I would Highly appreciate It!

0
code block please woodengop 1134 — 9y
0
Can you explain a bit more about what is wrong? Muoshuu 580 — 9y
0
First thing I can say is not right, is you do not have a end ('end)') to the function. Also, user doesn't seem to be defined in your script, so the player stats would not change. M39a9am3R 3210 — 9y
0
I feel bad for people who bought this already qq groovydino 2 — 9y

1 answer

Log in to vote
0
Answered by
Merely 2122 Moderation Voter Community Moderator
9 years ago

StarterGui is just a folder that contains all the GUIs for your game. When a player spawns, all the items in StarterGui are copied and pasted into that player's PlayerGui object, which is inside the Player. Instead of defining buyButton as game.StarterGui.ShopMain.MoneyButton, it should be something like script.Parent.ShopMain.MoneyButton based on where the LocalScript is in relation to the GUI.

In addition, instead of handling the cash adding on the client, it has to be done on the server by setting the MarketplaceService.ProcessReceipt callback.

ProcessReceipt Example: http://wiki.roblox.com/index.php?title=ProcessReceipt

So in your case, you might write something like this and put it in a Script (not LocalScript) in ServerScriptService:

local cashProductId= 23342953
local MarketplaceService = game:GetService("MarketplaceService")

MarketplaceService.ProcessReceipt = function(receiptInfo) 
    -- find the player based on the PlayerId in receiptInfo
    for i, player in ipairs(game.Players:GetPlayers()) do
        if player.userId == receiptInfo.PlayerId then
            if receiptInfo.ProductId == cashProductId then
               local stats = player:FindFirstChild("leaderstats")
        if stats ~= nil then
            local cash = stats:FindFirstChild("Cash")
            cash.Value  = cash.Value +3000
                return Enum.ProductPurchaseDecision.PurchaseGranted     
        end
            end
        end 
    end
end
0
I put that script inside of ServerScriptService, but What do i put inside the gui? im very confused iiZexyii 0 — 9y
Ad

Answer this question