I just wanted to know if it would be possible if I could put these functions into one module script, or would I have to put each function into a seperate Module Script?
01 | wait ( 3 ) |
02 | NPC = script.Parent |
03 | Children = NPC:GetChildren() |
04 | humanoid = NPC.Humanoid |
05 | IsHurt = false |
06 | SpawnPos = NPC.Spawn.Position |
07 | humanoid.Health = humanoid.Health - 5 |
08 | print ( "An NPC named: " ..NPC.Name.. " has been born" ) |
09 |
10 | function ContinueWalking() |
11 | NPC.Busy.Value = false |
12 | while NPC.Busy.Value = = false do |
13 | wait (math.random( 4 , 6 )) |
14 | humanoid:MoveTo(Vector 3. new(SpawnPos.X, 7.4 , SpawnPos.Z) + Vector 3. new(math.random(- 90 , 90 ), 0 , math.random(- 90 , 90 )), NPC.Spawn) |
15 | wait (math.random( 3 , 6 )) |
Depends honestly, ModuleScripts aren't needed they are just a tool for organization, and that means you can organize them to your liking, organize the functions by what should call them or organize functions by how or when they are called. Honestly for these functions I would first add parameters so you can actually use the code in ModuleScripts, and then after that I would put them all into one ModuleScript with a loading functions which loads all the variables in the current ModuleScript.
something like this in the ModuleScript. (under the workspace)
01 | --functions and variables here |
02 |
03 | shared [ "lib" ] = getfenv () |
04 | local function Loader() |
05 | for i,v in pairs (shared [ "lib ] ) do |
06 | if i~ = "script" then |
07 | getfenv ( 2 ) [ i ] = v |
08 | end |
09 | end |
10 | end |
11 |
12 | return Loader |
So to require it all you would have to do is
1 | require(Workspace.ModuleScript)() |
As I said there are a billion ways to organize modulescripts, there is no right or wrong way its all your choice of organization. If I am not clear enough please comment and I'll willingly explain more :)