Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Creating a event/listener?

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.

1 answer

✓ Accepted answer

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.

1 comment

0

Thank you so much, for your help.

This discussion is preserved as it was. New answers, comments, and votes are closed.