I am working on a gui that allows players to use robux to buy in game items. The script for the buttons works in studio but does not work in actual game servers, despite it being a local script. When you click the button it is supposed to do the transaction and then give the player the item but instead it takes the money and doesnt give the player the item. Here is the code
01 | local plr = script.Parent.Parent.Parent.Parent.Parent.Parent |
02 | local link = game:GetService( "MarketplaceService" ) |
03 | t = 0 |
04 |
05 |
06 | script.Parent.MouseButton 1 Click:connect( function () |
07 | local marketId = 339021456 |
08 | link:PromptProductPurchase(plr,marketId) |
09 | link.ProcessReceipt = function (receiptInfo) |
10 | if Enum.ProductPurchaseDecision.PurchaseGranted and receiptInfo.PlayerId = = plr.userId then |
11 | if t = = 0 then |
12 | t = 1 |
13 | local give = game.Lighting.BuyableTools.Basketball:clone() |
14 | wait ( 1 ) |
15 | give.Parent = plr.Backpack |
If your game is Filtering Enabled
then this is most likely why, The client trust the server, but the server deosn't trust the client, so you can use Remote Events To tell the server its alright to make the changes. Example of a script I made.
ServerScript in ServerScriptStorage
01 | local GunShop = game.ReplicatedStorage.ShopEvents.GunShop |
02 |
03 |
04 | --Gun Shop Events-- |
05 |
06 | --Glock-- |
07 | GunShop.Glock.OnServerEvent:Connect( function (plr) |
08 | local Cost = 500 |
09 | if plr.IsLTCOwner.value = = true then |
10 | if plr.PlayerGui.Shop then |
11 | if plr.stats.Money.Value > = Cost then |
12 | local Weapon = game.ServerStorage.GunShop:FindFirstChild( "Glock" ) |
13 | local Cash = plr.stats.Money |
14 | Cash.Value = Cash.value - Cost |
15 | local Cloned = Weapon:Clone() |
16 | Cloned.Parent = plr.Backpack |
17 | end |
18 | end |
19 | end |
20 | end ) |
LocalScript
01 | local Price = 500 |
02 |
03 | local GunShop = game.ReplicatedStorage.ShopEvents.GunShop |
04 |
05 |
06 |
07 | script.Parent.MouseButton 1 Down:Connect( function () |
08 | local plr = game.Players.LocalPlayer |
09 | local money = plr.stats.Money |
10 | if money.value > = Price then |
11 | GunShop.Glock:FireServer(plr) |
12 | script.Parent.Parent.Parent.Information.Price.Text = "Thank you for your purchase!" |
13 | wait( 3 ) |
14 | if script.Parent.Parent.Parent.Information.Price.Text = = "Thank you for your purchase!" then |
15 | script.Parent.Parent.Parent.Information.Price.Text = Price else |
16 |
17 | end |
18 | end |
19 | end ) |