Suggestions for Scripts + tips

So I would like to ask for suggestions of small projects/systems that I could do to improve my general knowledge. I would also like to ask for suggestions on how to read the roblox api to gain knowledge about everything that is most commonly used. I’m not a beginner, but I would like to practice more. I started learning scripting a while ago and didn’t practice much

3 Likes

Here are a few I can remember from the top of my head.

Good writing practices

  • Leave comments. This helps you and everyone else organize what each part of the script is trying to do and will come in handy during debugging.
  • Correct indentation
  • Consistent variable formatting (camel case and pascal case) (i.e. myVariable or MyVariable)

Good scripting practices

  • Avoid long, nested if/else statements.
  • Avoid creating too many new threads (coroutines/task.spawn)
  • Handle object movement and effects on the client rather than the server
  • Do not define unnecessary variables (just useless extra memory existing in the stack)
  • Make sure your connections are disconnected after use
  • When instancing a new object, set its properties before you parent it (like workspace)
2 Likes

Variables

Uses

Don’t create variables to do not use they.
Example : Creating a variable to ReplicatedStorage and use game.RepliactedStorage on some lines.

Creation

Create a variable if:
Is a service
You will use 2 or more times
The path is long
Looks neccessary

Client vs Server

On client to evict errors use :WaitForChild

On server you can use . like:
workspace.Map server have the all data, but use :WaitForChild if the instances will be created while gameplay.

Name

For services use complete name or semi-name

ReplicatedStorage or ReplicatedS
TweenService or TweenS
UserInputService or UIS

For everything else use a name that you will remember or recognize.

Will help you do code.

Optimization

Do every variable local, they are better than globals.

Do client checks, effects on client, and cooldowns or checks on server.

You can re-use variables if your code is too large.

These are my tips

Now Ima leave bc I am mobile rn

1 Like

Actually I wanted projects that I can do to practice, these “best practices in scripting” most I already know

Personally, I would try to make a data storing framework. That was basically my first real project, and taught me a lot.

Ok thxxx. But, do you have tips of how to read roblox documentation? I need to get more knowledge

YouTube
The documentation kind of sucks
It can help but youtube helps more
Heres some tips aswell:
Optimization

  • Avoid large nested statements
  • Avoid global variables, make as many of them as possible ‘local’
  • If you’re using modules and you need a certain option for multiple types use OOP (Object Oriented Programming)

The Do’s

  • When using any service use :GetService
  • Dont use depracated functions and uses
  • Dont use free models
  • Use WaitForChild in local scripts, use FindFirstChild in server scripts.

The dont’s

  • Don’t create too many threads, like multiple coroutine / task.spawn
  • Don’t make unnecessary long variables like local ReplicatedStorage_Service = game:GetService("ReplicatedStorage")
  • Never trust the client, trust the server.
  • Do checks on the client and cooldowns and checks on the server.

Good Practices

  • Leave comments where needed with the NOTE: keyword (It highlights as blue-ish gray), example:
-- NOTE: Add x here at xx:xx:xx time.
  • Make sure you don’t have multiple connections without them being disconnected to block lag
  • Always set your objects data before setting it’s parent
  • Never use Instance.new("x", parent) it seems almost unnoticeable, but it has like a 0.053… millisecond delay