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

Buy button works in studio but does not work in game servers?

Asked by 6 years ago

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

01local plr = script.Parent.Parent.Parent.Parent.Parent.Parent
02local link = game:GetService("MarketplaceService")
03t = 0
04 
05 
06script.Parent.MouseButton1Click:connect(function()
07local marketId = 339021456  
08link:PromptProductPurchase(plr,marketId)
09link.ProcessReceipt = function(receiptInfo)
10if Enum.ProductPurchaseDecision.PurchaseGranted and receiptInfo.PlayerId == plr.userId then
11if t == 0 then
12t = 1
13local give = game.Lighting.BuyableTools.Basketball:clone()
14wait (1)
15give.Parent = plr.Backpack
View all 22 lines...

1 answer

Log in to vote
1
Answered by 6 years ago

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

01local GunShop = game.ReplicatedStorage.ShopEvents.GunShop
02 
03 
04--Gun Shop Events--
05 
06--Glock--
07GunShop.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
20end)

LocalScript

01local Price = 500
02 
03local GunShop = game.ReplicatedStorage.ShopEvents.GunShop
04 
05 
06 
07script.Parent.MouseButton1Down: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
19end)
Ad

Answer this question