Is it fine to put functions in a module script that I use only once? (just to make script more readable)

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.

Thanks to everyone who responds :slightly_smiling_face:

1 Like

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

Remember Module Scripts only return one thing.

Admin commands are in the server, the module is in the server script service.

1 Like

If the module is in ServerScriptService its completely safe from the Client, means you can implement as many functions as you’d like.

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)

You can do that it won’t make a big difference when you use it only in 1 script

2 Likes

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.

3 Likes

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 not effective? Its in ServerScriptSerivce its completely safe from the client due to the client having no access to ServerScriptService.

1 Like

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.

1 Like

I’m saying if it wasn’t, your code method wouldn’t work at all.

2 Likes

Thank you @DindinYT37 and @rogchamp. 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 :slight_smile:

1 Like

I know of people who have done a module for each command, so one for all the commands together is definitely okay.

2 Likes