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!
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