How would I give 5000 cash to someone when they click the gui? I have got this
--LocalScript in StarterPack -- setup local variables local buyButton = game.StarterGui.q.Frame.TextButton local productId = 20518668 -- when player clicks on buy brick prompt him/her to buy a product buyButton.MouseButton1Click:connect(function() game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer, productId) end) buyButton.MouseButton1Down:connect(function() --Script in BuyButton part -- setup local variables local MarketplaceService = Game:GetService("MarketplaceService") local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory") local productId = 20518668 -- define function that will be called when purchase finished MarketplaceService.ProcessReceipt = function(receiptInfo) -- find the player based on the PlayerId in receiptInfo for i, player in ipairs(game.Players:GetChildren()) do if player.userId == receiptInfo.PlayerId then -- check which product was purchased if receiptInfo.ProductId == productId then -- handle purchase player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 5000 end end end -- record the transaction in a Data Store local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_purchase_" .. receiptInfo.PurchaseId ds:IncrementAsync(playerProductKey, 1) -- tell ROBLOX that we have successfully handled the transaction return Enum.ProductPurchaseDecision.PurchaseGranted end
Local script inside of the TextButton.
id = 20518668 --dev product id script.Parent.MouseButton1Click:connect(function() p = game.Players.LocalPlayer game:GetService("MarketplaceService"):PromptProductPurchase(p, id) local MarketplaceService = Game:GetService("MarketplaceService") local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory") MarketplaceService.ProcessReceipt = function(receiptInfo) if p.userId == receiptInfo.PlayerId then if receiptInfo.ProductId == id then p.leaderstats.Cash.Value = p.leaderstats.Cash.Value + 5000 end end -- record the transaction in a Data Store local playerProductKey = receiptInfo.PlayerId .. "_got_" .. receiptInfo.PurchaseId ds:IncrementAsync(playerProductKey, 1) -- tell ROBLOX that we have successfully handled the transaction return Enum.ProductPurchaseDecision.PurchaseGranted end end)
There is still a problem it wont do anything when I press it.