Fire an event to a module script

I am unsure how to fire an event to a module script from a client script. I have the module script in ServerScriptService. The client (in a GUI in StarterGui) then says “modualScript is not a valid member of ServerScriptService “ServerScriptService””.

local event = game:GetService("ReplicatedStorage").revealAnswerEvent
local revealAnswer = require(game:GetService("ServerScriptService").revealAnswer) --error given

event:FireServer(playerAnswer) --should fire an event to the module script 

any ideas on how to get this working?

Try to use :WaitForChild(), or move the module script to ReplicatedStorage

Did you make a typo? “modualScript is not a valid member of ServerScriptService “ServerScriptService””

I think you meant ModuleScript, not ModualScript

I have noticed that however even after changing it, it still gives an error.

When using :WaitForChild(), it says Infinite yield possible on ‘ServerScriptService:WaitForChild(“ModuleScript”)’

I get a “Requested module experienced an error while loading” error if it is in ReplicatedStorage

Infinite yield is fine, on the second error it might that revealAnswer module script has an error.

The descendants of server services (ServerScriptService and ServerStorage) are not replicated to the client. Client code communicates to the server through RemoteEvents; server code receives events through those remotes and then can act accordingly. I’m not sure what revealAnswer is supposed to be but your LocalScript would not be able to access it.

revealAnswer is the name of the module script I am trying to fire an event to. This does not work as the event is not received by the revealAnswer script.

That’s my bad, I missed the require call. You would need a Script instance (implicitly server-sided if using Legacy RunContext) to require the revealAnswer module so it can run on the server and start receiving events from the client through the remote.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.