Beginner Scripters Guide To Better Scripts And Organization

I’m reposting and editing this since the original one wasn’t in the correct location…

For all beginner scripters this is the post for you. My ideal goal today was to make a post that interest and help new scripters organize and better some parts of their code. Now, lots of new scripters mainly use YouTube as their credible source when it comes to learning new things but sometimes scripters may watch videos that are old and use deprecated (outdated) things.

Now when I started I was making silly mistakes, I had lots of repetitive code, lots of unnecessary things that would sometimes destroy the performance of my code most scripters make lots of silly mistakes like this still (which is okay) but I want to show you how much organized, and optimized your code can be.

Misuse

Now some beginners tend to misuse some of the scripting services for example

task.wait and task.Delay

task.wait is really useful for while loops while loops can loop the the part of the code running it super fasts. While it loops you need to add a task.wait part so that the code waits a few seconds between each loop, or it might go so fast that the game is just very hard to work with and just breaks.

task.delay can be very useful for creating new threads and delaying them. Using task.delay will create a new thread and only delay that section of the code.

Some people would try to use coroutine and then use task.wait but why go through all of that when you have a simple tool, like task.delay right there for you?

task.delay(2, function() -- waits two seconds before running the code in the thread.
    print("Hello Mate")
end)

Modules Systems And Resources

Here on the dev forum there are many modules, and resources that scripters use that can organize scripting, for example: EasyNetwork - Creates remote functions/events for you so you don’t have to!Easy Network Easy network is a module that handles remote events, remote functions and more communication items all in one module. Very simple to use, all u have to do is Place it anywhere (recommended ReplicatedStorage), call it, and bind it and if you have any questions, the link above has all the answers.

Screenshot_499

The developer Forum can be a good resource provider due to it’s many members some of them may share your same concerns and you might all ready have the resource you need, just search for it!

Modules I want to get into the talk about modules because lots of beginners may not see a purpose for it, but there are many, one big purpose for it is reusability. Reusability (in module form of course) is where you require a module and call it to perform different actions. For example:

local moduleScript = {}

function moduleScript:InsertInstances()
    local basePart = Instance.new("Part")
    
    return basePart
end

function moduleScript.changeBasepartProperties(basePart : Part)
    basePart.Color = Color3.fromRGB(255, 255, 189)
end

return moduleScript

And then you use your code to perform actions.

local moduleScript = require(moduleScriptLocation) -- location of your script

local basePart = moduleScript:InsertInstances() -- get the returned basePart

moduleScript.changeBasepartProperties(basePart)  -- change the basepartcolor

As you can see the script got the basepart from the module, then inserted it into a different part of the module to change the colour.

WaitForChild

I want to quickly explain the use of WaitForChild and when to use it.
Wait For Child basically just waits for an instance, and if that instance doesnt exist it will stop your whole script until it does. If your item takes to long and the script cant find it. You will get this error:

This is just notifying you that your script will yield forever because it cant find an instance. So please don’t use wait for child on certain objects cause it can mess up performance with your script.

Lastly Naming and organizing Variables
Naming and organizing variables was always something I have trouble with even now. Down below I will give some tips on how you can name some things and give the scripts an organized look.

local utiltyFolder = script.Utilities -- organize utilities in a folder

local moduleHandler = require(script.Module) -- gets help from the module

--[[
   heres some things u can call your variables or scripts.
   
   Functions,
   Utilties,
   Data,
   Tables,
   Dictionaries,
   Handlers,
   Organizers,
   Modules,
   Frameworks,
]]

also note that you can also probably start making the variable first letter lowercase, Idk its just fun :))

Anyways that’s all for teaching today, I hope you learned something and don’t mess up and make the same mistakes I did while I was in my beginner stage. Have fun scripting!

12 Likes

This tutorial is really something…

2 Likes

There’s no need for that rude language here… I’m just giving my comment to help you improve in the future.

Oh boy, that is a great joke dude!

1 Like