Any good housekeeping scripting practices?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Trying to get public opinion on best housekeeping scriping practices.

  2. What is the issue? Many times I feel like my code is messy and memory consuming, it works but its hard to understand.

  3. What solutions have you tried so far? I have improved the use of comments and I subsituted many while loops detecting things with events.

Any more practices regarding general scripting things (ex. use :WaitForChild() instead of bluntley defining variables) are welcomed here! :smile:

1 Like

With my self-diagnosed “OCD”, I like to make sure my code is organized in an orderly fashion. I tend to keep comments at a minimum (which I highly recommend not to do), but I really do love to organize my scripts through sectioning different functionalities and utilizing good syntax practices.

Be sure to utilize indentation. Indenting is very important if you are looking to make your code look nicer and more readable.

Here is how I might section my scripts to make them aesthetically pleasing:

--Services--
local UIS = game:GetService("UserInputService")
local RS = game:GetService("ReplicatedStorage")

--Fixed Instances--
local Player = game.Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
local Building_Info = PlayerGui:WaitForChild("Building Info")
local Template = script:WaitForChild("Template")
local Mouse = Player:GetMouse()
local Remotes = RS:WaitForChild("Remotes")
local RSDebris = RS:WaitForChild("Debris")
local VPTemplate = RSDebris:WaitForChild("ViewportTemplate")
local Placeables = RS:WaitForChild("Placeables")
local Placement_Controls = PlayerGui:WaitForChild("Placement Controls")

--Modules--
local Placement = require(game:GetService("ReplicatedStorage"):WaitForChild("Modules"):WaitForChild("Class"))
local ObjectModule = require(RS:WaitForChild("Modules"):WaitForChild("Object_Level Module"))
local placement = Placement.new(Player:WaitForChild("Plot"):WaitForChild("CurrentFloor").Value)

local isMobile = UIS.TouchEnabled

--Variables--
local tableModel = nil
local rotation = 0
local moveRotation = 0

Obviously, it doesn’t look the NEATEST. It does look much more organized than scrambling around a bunch of variables with a bunch of numbers along with module scripts. This is how I approach my code :slight_smile: Feel free to bake me!!!

2 Likes