Remote event gives extra item every time its fired

You can write your topic however you want, but you need to answer these questions:

  1. Q: What do you want to achieve? Keep it simple and clear!
    A: I have a shop and when you click the item it fires remote event that gives you the tool.

  2. Q: What is the issue? Include screenshots / videos if possible!
    A: Every time I click it is giving me more tools as showed below.

    First Time . … … … … 1 Tool
    Second Time … … … 2 Tools
    Third Time … … … … 3 Tools
    n Time … … … … … … n Tools

  3. Q: What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    A: Actually this is the second time I am making a topic about this one. But the first one didn’t help me much because it was about changing the :Connect() to :Once() and it works but I want to make player be able to purchase item again and again. The guy said: “You are connecting the event too many times, it gives extra every time.”

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Below all my scripts about this:

  1. GUIReplicator : LocalScript
  • Used to generate the GUI using template GUI and template cells for items. Then relocates the GUI into the PlayerGui. Fires an remote event when clicked on item.
  • Has 3 children:
    • Items : Folder
      • Contains items to be placed in GUI.
    • TemplateShopGUI : ScreenGui
    • TemplateCell : Frame
      • Contains a viewport frame to display the item.
  • Github - GUIReplicator
  1. ValidateScript : Script
  • Used to handle remote event and check if player has enough cash, then gives the tool and fires the remote event back with arguments: RespondTable and HashGUID.
    RespondTable has 2 entries. First one is used to know if succeed or fail. Second one is a GUID created per every item and sent to ValidateScript by remote event. This argument is used to make sure it is the correct process.
  • Github - ValidateScript
  1. LeaderstatsScript : Script
  • I won’t put the script here because it is too simple and I am sure that the problems source is not it.

Also the first topic is here too, but reminder that I changed the scripts and they have a little difference. Also their name is changed.

Devforum - Topic

I couldn’t find any solutions. Appreciate if you can!

1 Like

I don’t understand what you mean by the tools is given multiple times. Do you mean the player can buy multiple of the same items despite having only 1 available in stock? Well in that case you’re forgetting to remove the tool from its stock container from after the player purchases it.

I also recommend you add some sort of debounce to the player (maybe using a table) while they’re processing the transaction to prevent spamming it.

I have the tool in server storage and the script clones it then gives it to player.
But every time I buy, it gives me more like below.

The first click … … … … … … … 1 given
The second click … … … … … 2 given
The third click … … … … … … … 3 given

But the table above shows how much it gives. In the third click in total it is giving 1 + 2 +3 = 6 tools.

Also player can’t spam because there is a color animation on the cell border and the function returns if any of these tweens are playing. And the tween is starts to playing when cell clicked.

Actually this topic was for a long time ago. But I remember I solved it already by myself.
For anyone who lives this too I leave the script below.

local tool = script.Parent
local toolEnabled = false

tool.Equipped:Connect(function()
   toolEnabled = true
end)

tool.Unequipped:Connect(function()
   toolEnabled = false
end)

tool.Activated:Connect(function()
   if toolEnabled then
      -- Your code here
   end
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.