So, I’m trying to pass the various Tools scripts I have (which do the same thing) to a ModelScript, but I’m getting an error:
The first is from ModuleScript, the second is from LocalScript that is trying to Require the Module:
This is the part of the code that ModuleScript is generating an error:
local PickModule = {}
PickModule.Tool = script.Parent.Parent
PickModule.player = game.Players.LocalPlayer
PickModule.character = PickModule.player.Character or PickModule.player.CharacterAdded:Wait()
print(PickModule.character) --> Prints correctly
PickModule.ToolEquipped = false
PickModule.debounce = true
PickModule.ToolActivatedd = false
--// Folders \\--
PickModule.Animations = PickModule.Tool:WaitForChild("Animations",3)
PickModule.Remotes = PickModule.Tool:WaitForChild("Remotes",3)
PickModule.Configs = PickModule.Tool:WaitForChild("Configs",3)
--// Animations \\--
PickModule.HoldTrack = nil
--Line that the error is generated:
PickModule.PickDown = PickModule.Animations:WaitForChild("PickDown",3)
With the second argument as 3, it’ll only wait for a maximum of that amount of seconds before returning nil. I’d suggest removing this unless it’s absolutely necessary.
Remove the number argument from all the WaitForChild functions, it should not be used to get things you know for sure will exist, that is things you place in the respective locations in studio.
I realized that I can’t put the variables in ModuleScript, so I leave them in LocalScript and the functions are all in Modules. I don’t know if this is the correct way to think about ModuleScripts, however this is the way I managed to solve my error.