Soooooo, i have over 2 years of scripting but i still cant get a solution for this:
What do you want to achieve? I want to script faster, better, and efficiently, i feel like i waste hours for something that looks simple, im almost hopeless and quitting scripting, doing animations instead, building, doing meshes, when i get a bug, it also takes a while to fix it, i dont know if scripting is like that, or if im doing something wrong
What is the issue? That i dont know how to script better, faster, and i still dont
What solutions have you tried so far? Didnt found something helpful in youtube or devforum
I really have no idea why this happens, if you can help thanks! if you cant, is ok, i will be waiting for answers.
That comes with experience, the more code you write, the more you will find good and bad practices and the more efficiently you can code. A small tip is to always look for optimizations in resource intensive algorithms. If u have a big chunk of code that does so much, search for optimization methods, you will surely find at least one or two methods and multiple explanations saying why and how they work. The more you search the more information you will gather. It’s just a matter of time.
This happens, even to the best of us. A good way to overcome this is planning. Don’t just open Roblox Studio or VSCode and start typing random code. Sit down, open apps like draw.io or Trello or even using a pen and paper. Write down what u want to make and break it into chunks, then break those chunks into even smaller chunks. You will end up with way more stuff to do but they are all smaller, simpler, and more importantly, neatly organized. Make sure to not go too small in the chunks, you will find the reasonable size that your code needs to be broken to when making the project, there isn’t anything like a pre-defined amount or so. Then slowly code each of these chunks and it’ll feel way easier.
That is also normal, I once encountered a bug that took almost 4 hours to solve. It takes time to do the research and find the correct answer, I mean, yes my bug was in a big and complicated algorithm but it’s still a bug like any other bug in your or my code. Some bugs can be fixed in less than a minute and others may take ages.
thanks! i will try next time i start to script! you think i should make like a big script into two small ones? or use functions to make it smaller? or even module scripts?
Personally I like to have some rules for how I code.
A file/script should never exceed 300 lines.
A function should do a small part of a big thing, except if the function is made to make the code smaller, for example, if u have 3 instances that the same big chunk of code needs to be applied to, make a function that takes a parameter of the instance and does that big chunk.
Classes (OOP) should be used, instead of making a gun with all it’s stuff inside it, only have a config file inside the gun and create a global “Gun” class, that makes it easier to edit core functionality and, if an error is found, you only have to edit one!
Module scripts are a must there’s a 100% chance you have a repeated part of code in multiple scripts that can become a function in a module script.
When you write code for the first time, it’s never perfect. Focus on functionality, after you get a 100% functional code, you should now make it cleaner, more readable, optimized, etc. Before moving on to whatever the next thing you will do is.
Indents, please! Reading bad indented code is painful. Seriously, you NEED good indentation.
Don’t use abbreviations for names
Keep your naming conventions constant
Keep your coding style constant
Some of these are unrelated to your original question but they are still helpful so decided to include them.
This all comes down to experience. I see a lot of new people wanting to “script just for the sake of it”.
I always like telling people this: Scripting is a means, not an end.
It’s a means to make your project, game… Whataver. Searching for a tutorial won’t help you because you need experience.
I also saw you mentioning making scripts “smaller”. I own a game with 25M visits and the main code is 3K whole lines of code. Length doesn’t matter as long as it accomplishes what you wish. As I’ve said, Scripting is a means, not an end.
Don’t stress it, and learn from your mistakes. That is the way!