Hi so I’ve been scripting for about 3 years on and off and have never really looked into the exact proper and most readable way to set things up when I code and kinda need help since I’ve been doing it my own way for so long.
So I just want to know how professionals would say space variables apart from stuff like setting variables and then functions from variables etc how they all should be spaced from eachother?
Heres some example of what I’m wondering.
I know this example is random but I Just want to know in this case is it spaced right should variables be moved? etc…
local Players = game:GetService("Players")
local Hey = "wow"
local Super = "wow2"
if Super then Super = Hey end
local function CheckSuper ()
local Stuff = false
if Super then
print(Super")
end
return true
end)
Players.PlayerAdded:Connect(CheckSuper)
To add more information to this I’m wondering stuff like Should Variables like Services such as Players be spaced apart from Variables like Hey and Super? Should statements like If Super then Super = Hey end be spaced away from everything else?
I don’t really think there’s such thing as “Professional” when it comes to organization (or spacing), in your script. It’s really just what you prefer. Although, I will advise to be sure to space variables away from functions. Also, have as many variables at the top of your script as possible, It’s just easier.
(Ex. If I’m going to use the variable “Map”, but only use it near the middle of the script, still define it at the top. It makes it easier to change it/ see it’s there)
Also, things you are going to use more often, I like to make stand out (Might just be me)
Here’s a snippet of spacing I used:
--Server
local replicatedStorage = game.ReplicatedStorage
local serverStorage = game.ServerStorage
local playersService = game.Players
local lightingService = game.Lighting
local chatService = game.Chat
local serverScriptService = game.ServerScriptService
local workspaceMap = workspace.Map
local fallDamage = false
local lobbySpawns = workspace.LobbySpawns
local mapsStorage = serverStorage.MapsFolder
local events = replicatedStorage.Events
local values = replicatedStorage.Values
local mainString = values.MainString
local INTERMISSION_TIME = 18
Thankyou for responding, so variable wise should I keep services and stuff like lighting etc seperate from my cooldown variables and like my bools seperate from my number variables etc? also like if I have a function at the end of a script but need to return true at the end should I space between the function and return true? Also if I have to connect a event to a function should I have the Connection part touching the bottom of the function?
I prefer to space variables for services, variables for objects, bool variables, etc
I might not understand your question but I think that answers it. If this doesn’t fully answer your question, could you try typing your code (Just what you’re confused with)
local function Hey()
end
--Should a space go right here?
game.Players.PlayerAdded:Connect(Hey)
if this then
print("s")
--Should a space go right here?
elseif that then
print("T")
end