What does setting an event equal to a function do? (script below)

I was looking at the api for RemoteFunctions and noticed the code:

getHelloWorld.OnInvoke = function()
	return HELLO_WORLD
end

Why do they use ‘=’? Couldn’t they do

getHelloWorld.OnInvoke:Connect(function())
	return HELLO_WORLD
end)

Don’t take my word for it, but…

The two are pretty much interchangeable, except calling :Connect takes up more memory and opens the door for memory leaks if they’re not canceled, so it’s probably just proper practice to call it the first way.

When you say ‘cancelled’, that means disconnected, right? Thanks!

1 Like