Equipping System in Inventory GUI

Hello, I am finishing up my inventory system but ran into some problems. Everything works fine when I am equipping an item. However, when I try to unequip the item it multiplies how many requests it sends to the module function.

Main.ChildAdded:Connect(function(Child)
	if Child:IsA("TextButton") then
		Child.Activated:Connect(function()
			Inventory:FireServer("Equipping!", "Primary", Child.Name)
		end)
	end
end)

Primary.ChildAdded:Connect(function(Child)
	if Child:IsA("TextButton") then
		Child.Activated:Connect(function()
			Inventory:FireServer("Unequipping!", "Primary", Child.Name)
		end)
	end
end)

This checks if an item is added to the inventory and assigns an .Activated event to it.

function Inventory:Unequip(Player, Type, Item)
	if self[Player][Type][Item] then
		self[Player].Items[Item] = self[Player][Type][Item]
		self[Player][Type] = {}
		
		InventoryRemote:FireClient(Player, {"Unequipping", Type}, Item)
		print("hi")
	end
end

The aforementioned issue makes it so that every time I click the item to unequip, it will print
hi two times, and it will multiply the requests everytime I click the Button instance: it will print “hi” 4, 8, 16, 32 times etc.

Perhaps add a debounce? If your script is exactly what you have shown, then a debounce may be what you are looking for.

1 Like

Hello, I tried adding a debounce to the Activate event, however, this did not work. I could try it on the server, and the module function will only run every time the debounce is disabled, but the multiplied amounts of requests being sent from one button click will be a problem. (I updated the post)

Maybe show us the whole script

1 Like

Hello, I do not think I need to show the whole script, since the other lines mostly handle GUI work and module table manipulation, which works fine. I just showed the snippets of the Activated event and the Unequip function of my module since those are the relevant factors for my issue I believe.

Pushing this on top, I still need help regarding this problem