Problem with bindable event

  1. What do you want to achieve? Keep it simple and clear!
    So basically i’m making an tycoon and using an bindable event in tycoon module using self

  2. What is the issue? Include screenshots / videos if possible!
    for some reason while i’m getting when event is fired it says:
    image

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub? I was making this by youtube video and it should work.

Here is part of code(in case other part of code is not connected with event)

self._topicEvent = Instance.new("BindableEvent")
...
function Tycoon:SubscribeTopic(topicName, callback)
	local connection = self._topicEvent.Event:Connect(function(name, ...) -- here is error
		if name == topicName then
			callback(...)
		end
	end)
    return connection	
end

When you create the bindableEvent, self should not be used, instead you should use the table that the function is located in.

This is because self is set to actual table inside the function.


Tycoon._topicEvent = Instance.new("BindableEvent")
...
function Tycoon:SubscribeTopic(topicName, callback)
	local connection = self._topicEvent.Event:Connect(function(name, ...) -- here is error
		if name == topicName then
			callback(...)
		end
	end)
    return connection	
end

2 Likes

Hm Well it works, maybe self with bindable event is deprecated now, in case in video it works fine.

1 Like

The problem is that ‘self’ inside the method overwrites (shadows) the upvalue (non-local variable) of the same name.

1 Like