Require not working in some modulescripts even tho they have the same reference

so i have trying to make a scratch project in roblox (https://scratch.mit.edu/projects/580314315/) and well i decided to use 4 module scripts (1 for the enemy (the smiler), 2 for the player, 3 for utils and 4 for the main initializer) so i can only load the entire thing at once

the initializer has this function named “new” which returns a metatable with variables like the ui, player, localplayer, elements for convinience

but in the other modulescripts when i try to require the initializer, the functions just dont show up
for some reason it only shows up in the smiler module
when i tried running it, the control errored “…Modules.Player.controls:21: attempt to index nil with “MoveDirection””
i think the main cause of this is because new just doenst exist in that module

this is basically what happened


i used the roblox playermodule as reference to my modules btw thats why it shows up in the explorer

does anyone know why this happens and how to fix it

In the Initializer you set self.humanoid to the Player’s Humanoid but in the Controls module you write self.hum.MoveDirection. Since self.hum is not set to the Humanoid but rather to nil/not set, the error occurs . You need to write self.humanoid.MoveDirection. instead.

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