Why is my Keyboard Module Script not registering as a child of my Control Script?

image
I am trying to initialize the Keyboard Module Script in ControlScript with this:

local Keyboard = require(script.Keyboard) -- Initialize Keyboard

but it gives me an error of:
Keyboard is not a valid member of LocalScript
So I tried making it

local Keyboard = require(script:WaitForChild("Keyboard"))

but it gave me the infinite yield warning
and I tried:

local Keyboard = require(script:WaitForChild("Keyboard",1))

But it gives me the error: Attempted to call require with invalid argument(s).

Am I genuinely doing something wrong or is this just a studio bug?

EDIT: I’m fairly new to module scripts also just to let you know.

I was not able to reproduce the error you are getting after using the same steps. Try doing it in an empty baseplate with just those two scripts. Same result?

I created a new place and it worked it must have been a studio bug but I am not sure.

Or perhaps another script interfering with it? Up to your decision haha

3 Likes

Have you tried keeping the Module in another place? Maybe store it in ReplicatedStorage and see how that goes.

To verify if the module remains there, check the player’s PlayerScripts at runtime. Check if the module is still there. If it isn’t, something else is removing it.

Try disabling the other scripts in your game one by one and see which one allows the module to remain there. The fact that it works in an empty baseplate leads me to believe that some part of your game is removing the module.

I’ve come across this several times and my conclusion is that you need to reference the module like: StarterPlayerScripts.controlScript.keyboard

Pretty sure it has to do with the cloning of the contents to every player.

I created another place and put the scripts in the same location, it worked. Next time if this happens I will try what you said. Thanks!

Cloning is synchronous. If ControlScript is available, so is its descendants. Going all the way back around to reference StarterPlayerScripts is pointless overhead when you can index the child directly. If you want to wait for availability, there’s WaitForChild.