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.