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

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

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

local plr = script.Parent.Parent.Parent.Parent.Parent.Parent
local link = game:GetService("MarketplaceService")
t = 0


script.Parent.MouseButton1Click:connect(function()
local marketId = 339021456   
link:PromptProductPurchase(plr,marketId)
link.ProcessReceipt = function(receiptInfo)
if Enum.ProductPurchaseDecision.PurchaseGranted and receiptInfo.PlayerId == plr.userId then
if t == 0 then
t = 1
local give = game.Lighting.BuyableTools.Basketball:clone()
wait (1)
give.Parent = plr.Backpack
local give2 = give:clone()
give2.Parent = plr.StarterGear
t = 0
end
end
end
end)

1 answer

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

local GunShop = game.ReplicatedStorage.ShopEvents.GunShop


--Gun Shop Events--

--Glock--
GunShop.Glock.OnServerEvent:Connect(function(plr)
	local Cost = 500
	if plr.IsLTCOwner.value == true then
		if plr.PlayerGui.Shop then
				if plr.stats.Money.Value >= Cost then
				local Weapon = game.ServerStorage.GunShop:FindFirstChild("Glock")
				local Cash = plr.stats.Money
				Cash.Value = Cash.value - Cost
				local Cloned = Weapon:Clone()
				Cloned.Parent = plr.Backpack
			end
		end
	end
end)

LocalScript

local Price = 500

local GunShop = game.ReplicatedStorage.ShopEvents.GunShop



script.Parent.MouseButton1Down:Connect(function()
	local plr = game.Players.LocalPlayer
	local money = plr.stats.Money
	if money.value >= Price then
		GunShop.Glock:FireServer(plr)
		script.Parent.Parent.Parent.Information.Price.Text = "Thank you for your purchase!"
		wait(3)
		if script.Parent.Parent.Parent.Information.Price.Text == "Thank you for your purchase!" then
			script.Parent.Parent.Parent.Information.Price.Text = Price else
			
		end
	end
end)

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