Can someone explain to me what event listeners are and how to use them?
Listening in this context means to wait for a signal or call and do something about it. Events are listeners, because they listen for something to happen (.Touched
waits until a part touched) and they do something when they detect something. Remote events are listeners, they listen for a signal from either the client if the remote event is listening from this server, or from the server if the remote event is listening from the client. You :FireClient()
for example, and listen for that using OnServerEvent
. People will use different terminologies most of the time. An event listener might just be referring to OnServerEvent
.
When you call connection:Connect(callback)
the callback or listener you pass is invoked when the event fires.
-- Remote.OnServerEvent -- event
local function OnEvent() -- callback
end
Remote.OnServerEvent:Connect(OnEvent) -- connecting listener/function to the event, so whenever the event fires, the callback function executes.
Event listeners are called in a new thread each time.