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

Developer Products Script Help?

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!

4 comments

0

code block please

0

Can you explain a bit more about what is wrong?

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.

0

I feel bad for people who bought this already qq

1 answer

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

1 comment

0

I put that script inside of ServerScriptService, but What do i put inside the gui? im very confused

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