Hello!
Weird thing. I have a Shop with multiple shop windows -Shop A, Shop B, etc., with one RemoteEvent that handles the purchases.
If you make a purchase in Shop A, you're charged once. if you close Shop A and open Shop B to make a purchase, you're charged twice. Close Shop B and open Shop C, you're charged thrice. etc. etc. The player does receive the item - or in this case a BoolValue is set to True - but I don't want them to be charged multiple times for closing one Shop and opening another one.
I've narrowed down the problem, I think, to my RemoteEvent Script in ServerScriptStorage:
--//Get Services local ReplicatedStorage = game:GetService("ReplicatedStorage") --//Event local Events = ReplicatedStorage:WaitForChild("Events") local UpgradesCoinsPurchase = Events:WaitForChild("UpgradesCoinsPurchase") UpgradesCoinsPurchase.OnServerEvent:Connect(function(Player, Value, Amount) Player.leaderstats.Coins.Value = Player.leaderstats.Coins.Value - Amount --Subtract money from the player print(Value) Value.Value = true end)
Here is what the Buy Button box Local Script looks like, I cut out the irrelevant stuff. The Value, ItemPurchased, and ItemTrackName values are changed by pressing a button in each shop:
--//Get Services local RS = game:GetService("ReplicatedStorage") local Players = game:GetService("Players") local Player = Players.LocalPlayer local currencyCOINS = Player.leaderstats.Coins --//EventFolder local Events = RS:WaitForChild("Events") local UpgradesCoinsPurchase = Events:WaitForChild("UpgradesCoinsPurchase") --//SHOP FRAME Variables local PurchaseFrame = Frame.PurchaseFrame local BuyButton = PurchaseFrame.BuyButton local Price = PurchaseFrame.Price local ItemTrackName = RS:WaitForChild("ItemTrackNameShop") local ItemPurchased = RS:WaitForChild("ItemPurchased") BuyButton.MouseButton1Click:Connect(function() MenuClickSound:Play() local amount = Cost local Value = ItemPurchased.Value if Player.Inventory[Value].Value == true then wait(3) else if Player.leaderstats.Coins.Value >= amount then UpgradesCoinsPurchase:FireServer(Player.Inventory[Value], amount) wait(1) PurchaseClickSound:Play() wait(3) PurchaseFrame.Visible = false wait(1) else local coinsrequired = amount - currencyCOINS.Value wait(5) PurchaseFrame.Visible = false end end end)
Any thoughts? I've tried creating multiple RemoteEvents to handle each shop's transactions, but that only caused duplicate purchases. I tried putting each shop's windows purchases in its own Local Script, but that made no difference. My next thought is I need to put all 120 items for purchase in a single window, or create a separate Shop GUI for reach Shop.
I am open to suggestions in the meantime. :D
Thank you!