Why ModuleScript's "BindToMessageParallel" errors if called inside a function

I have a module script inside a actor

ModuleScript’s Code:

local module = {}

function module.start()
	local actor = script:GetActor()
	actor:BindToMessageParallel("idek", function(data)
		print(data)
	end)
	print("bind")
end

return module

Script’s Code

require(game.ServerScriptService.Actor.ModuleScript).start()

This will give this error

But if removed from a function
(Code)

local module = {}

local actor = script:GetActor()
actor:BindToMessageParallel("idek", function(data)
	print(data)
end)
print("bind")

return module

And remove the “.start()” from the Script (Otherwise it will try to call nil ofc lol)
It won’t error

Ok I see, but why
If you call function from module it works

the function runs in the context of the script you required it from
but if you require it and run the code in the module script without a function its gonna run from the context of it being under an actor (since the module script is under an actor)
basically functions run under the script context and not the module

You try to communicate to a diffirent VM without using proper channels such as BindableEvent/Actor API

Its obviously not possible; Don’t do that.
Instead turn this module into a regular script and communicate to script through Actor

You seem to not undestand how Actor and ModuleScript works.

Also what is the point of having this function anyway?

local actor = script:GetActor()
actor:BindToMessageParallel("idek", function(data):()
	print(data)
end)
print("bind")
return nil

Would make more sense


Solution:

Turn ModileScript into a regular script

local actor = script:GetActor()
actor:BindToMessageParallel("idek", function(data):()
	print(data)
end)
print("bind")
actor:SetAttribute("Init",true)

Calling:

local Actor = game.ServerScriptService.Actor
if not Actor:GetAttribute("Init") then Actor:GetAttributeChangedSignal("Init"):Wait() end
Actor:SendMessage("idek","Hello")