I need some help understanding how require() works and how to use it.
So say you have a module script. If you want to access the code or functions inside of it, you use the require function.
local module = require() --path to module
module.RandomFunc()
end
ModuleScripts? Lol Idk how to use ModuleScripts. I just thought it’s something related to Scripts or LocalScripts as those are the ones that I know how to use currently, but thanks for help!
Require requires modules both online and offline, retrieving the value they return for others scripts. Most ModuleScripts return a table of functions. However, they can return anything.
You’re welcome! Module scripts will come in handy later as you can control everything with them.
I just thought it’s something related to Scripts or LocalScripts, as Idk how to use ModuleScripts yet, but thanks for trying to help!
ModuleScripts make code look clean. They are usually used to differentiate code into different categories and use logic outside the main function.
Usually when you are trying to use/call a modulescript you will need to require it.
local Module = require(<TheModuleScriptPath>)
It’s basically a standard to start up the module script
DM me if you help with module scripts or anything!
I just thought it’s something related to Scripts or LocalScripts, as Idk how to use ModuleScripts yet, but thanks for trying to help!
I will if I need help with anything! Thank you:)
You ok? You said that like 3 times bro. Do you need a ModuleScript tutorial or something?
Count it as external functions. You can have many things crowded into a piece of code so you could just call some modules and make it more clear like a module for setting the player’s fov or a module for setting the players’ currency. Usually a function over 200 lines is counted as big so it would be best to minimize it’s content for making it clean and easy for understanding.
No, I just wanted to remind you that I thought it’s something related to Scripts or LocalScripts. Idk how to use ModuleScritps, and no I don’t need a tutorial.
ModuleScripts are called from GlobalScripts or LocalScripts. They are no ordinary that run by themselves like the once mentioned.
If you know how BindableEvents work you could relate it to that.
1- Idk how to use BindableEvents
2- Idk how to use Remote Events or functions
I’m still a beginner.
Here this page should help:
I tried reading the documentation already, but it doesn’t efficiently help because my main language isn’t English. Even I tried translating it to my main language, but I still don’t understand smoothly. That’s why I’m planning on reading it when I grow up because when I grow up, my English skills will grow up as well.
Well if you are making small games with a lots of scripts, you wouldn’t necessarily need module scripts. They are just optional if you are going to make games that a lot of other people will read your code. If you are working as a solo developer you can script however you’d like.
Require
executes code in a module script and returns its value.
e.g
Module script
return "Returns test"
Normal script
local module = require(module.path)
print(module) -- Prints "Returns test"
Okay! My game doesn’t require many scripts. It actually does but they’re repeative, but thanks for letting me know!