Hello everyone! I am working on my own admin commands, and I created many functions (e.g. teleportation, killing, resetting, exploding and etc) and they make the script look a bit messy and big (in my opinion).
So I was wondering, is it fine to put all of the functions in a module script, even if I use it only in a single script?
In my opinion, that looks so much better, the script is shorter and easier to read.
You could put them in a ModuleScript but you would have to either secure it much (using codes in the function etc.) or you have to expect many exploiters using your admin commands.
Example how to secure a function:
function yourfunction(something,code)
if code == "Somerandomgeneratedcodebyyou" then
-- do command
end
end
Yes, I know, but is it okay to place the functions in a module script to make the code more readable and cleaner? I mean, instead of putting them directly in the script. I am using the module only in 1 script.
And @jumbopushpop112 yes, I know, they return a table of whatever I put in them (functions , variables and etc)
This isn’t a very effective method of security. Running the function on the client will just run it on the client, so there’s no reason to even try to secure it. Even if it did run on the server, somehow, it’s incredibly easy for an exploiter to just look inside the Module. Security through obscurity isn’t actual security—it just seems like it works for a little bit.
@OP: This should be fine, I’ve done it before. Even if you’re only using it in one place, being able to separate the commands themselves from the handler makes it cleaner and allows you to access both bits easier. I don’t think this would be an issue.
Thanks for answering. I am confused about whether I should do it or not. Because as I understood, functions are made for us to not repeat ourselves. But as I understood from some other people. Just using module scripts like that is not a good habit. Are you sure about that? Is it a fine thing to do?
How would it be not effective? Since the Script is located in ServerScriptService it’s completely safe from the client due to the client having no access to ServerScriptService.
You can do it due to the client not even having access to where the Module is located, if the Module is in ServerStorage or ServerScriptService you can do it.
Thank you @DindinYT37 and @posatta. I just wanted to make sure that it’s a fine (not related to security) thing to do. I wanted to make sure it’s okay since I understood from someone that it isn’t, and I didn’t want to repeat what I thought was a mistake.
Have a great rest of day/night