I'm writing a peice of code for my backpack.
x = AddSlot(script.Parent.Container.Slot1) x.ItemAdded:connect(function(itemAdded) print(itemAdded) end) x.ItemRemoved:connect(function(ItemRemoved) print(ItemRemoved) end)
If you look at line 3&4 how Would I make it be able to do that.
Very simply, by utilizing the ROBLOX-provided LuaSignals.
I'm assuming here that your AddSlot
function returns a Table:
local CreateSignal = LoadLibrary('RbxUtility').CreateSignal function AddSlot(slot) local newSlot = {} --code newSlot.ItemAdded = CreateSignal() newSlot.ItemRemoved = CreateSignal() end
Now, on its own, this does nothing, and I can't write the code to make it do something without seeing the rest of the AddSlot
function.
What you need to do is call the fire
method on those two LuaSignals, passing in the item that was added/removed, wherever you handle adding/removing items from Slots.