Why do you put spaces in between your code?

I have noticed in the scripting tutorials that I have watched(I’m not done cause I keep rewatching them to make sure I get the basics right) that they will put a space in between the code, like this:

game.Workspace.Baseplate.Transparency = 0.3

wait(5)

game.Workspace.Baseplate.Transparency = 0.5

Why can’t they do it like this:

game.Workspace.Baseplate.Transparency = 0.3
wait(5)
game.Workspace.Baseplate.Transparency = 0.5

Thank you in advance!

Sometimes people just want them to be neat?

2 Likes

This is totally preference, from my perspective.

Given your example, I would personally probably prefer to not do spacing, as that’s one chunk of code I comprehend it as. (setting transparency of the same part after time has elapsed.)

Some practices I’ve been trying to use is create “chunks” of similar code and then space it out when a new chunk has been made. Here’s what I mean:

local BodyForce = Instance.new("BodyForce") --//One chunk relating to the BodyForce object
BodyForce.Force = Vector3.new(0, 90, 0)

local Blah = Instance.new("Fire") --//Another chunk relating to the Blah object
Blah.Size = 5
8 Likes

Like @Suuzv said to be neat and it’s easier to read the code when there is space.

1 Like

Sometimes, When doing big scripts code can get little bit messy. When you have 100+ lines of code its a bit confusing understanding which line of code does which. Putting spaces between code can allow you to differentiate between other chunck like different functions and events

2 Likes

Well its simple, I put spaces because I am obssesed with organizing my code.

2 Likes

I personally don’t put spaces like that - this is preference.

Some people find

line

line

line

more readable, I personally tend to only do this for new variables/events/functions

2 Likes

It also depends on what code you are writing so

Folder = instance.new(“Folder”)
Folder.Name = “Test”
Folder.Parent = player

Coins = instance.new(“Intvalue”,Folder)
Coins.Name = “Coins”

2 Likes

Readability.

You’re under no obligation to add whitespace to your code but for your own sanity and especially that of collaborators if you’re working in a team, you should include it. These characters are ultimately irrelevant in compilation and just help with human readability.

Not sure how Roblox compiles it though and if there’s any difference if you have whitespace. There shouldn’t be a difference though (primarily referring to speed) and it’ll still get compiled the same way.

1 Like

Usually people leave empty spaces, so the code wont lead to confusion and will be readable
Example :
image

image

Imagine not adding those extra spaces and comments, your code would look disorganized and ugly

3 Likes

This is the code for a semi-intermediate gui:

local screen = script.Parent.Screen
local creditsMenu = script.Parent.CreditsMenu
local playButton = script.Parent.Screen.Play
local creditsButton = script.Parent.Screen.Credits
local closeCredits = script.Parent.CreditsMenu.CloseCredits
local openGui = script.Parent.OpenGui
local pop = game.Workspace.pop

playButton.MouseEnter:Connect(function()
	playButton:TweenSize(UDim2.new(0, 210,0, 60), "Out", "Quad", 0.01, true)
end)
playButton.MouseLeave:Connect(function()
	playButton:TweenSize(UDim2.new(0, 200,0, 50),"In", "Quad", 0.01,true)
end)
creditsButton.MouseEnter:Connect(function()
	creditsButton:TweenSize(UDim2.new(0, 210,0, 60), "Out", "Quad", 0.01, true)
end)
creditsButton.MouseLeave:Connect(function()
	creditsButton:TweenSize(UDim2.new(0, 200,0, 50),"In", "Quad", 0.01,true)
end)

playButton.MouseButton1Click:Connect(function()
	screen:TweenPosition(UDim2.new(0, 0,1, 0), "Out", "Quad", 0.5, true)
	openGui:TweenPosition(UDim2.new(0.011, 0,0.444, 0), "In", "Quad", 1, true)
	pop:Play()
end)

creditsButton.MouseButton1Click:Connect(function()
	creditsMenu:TweenPosition(UDim2.new(0.499, 0,0.5, 0), "In", "Quad", 0.5, true)
	screen:TweenPosition(UDim2.new(0, 0,1, 0), "Out", "Quad", 0.5, true)
	pop:Play()
end)

closeCredits.MouseButton1Click:Connect(function()
	creditsMenu:TweenPosition(UDim2.new(0.499, 0,1.5, 0), "Out", "Quad", 0.5, true)
	screen:TweenPosition(UDim2.new(0, 0,0, 0), "In", "Quad", 0.5, true)
	pop:Play()
end)

closeCredits.MouseEnter:Connect(function()
	closeCredits.TextColor3 = Color3.fromRGB(255,0,0)
end)

closeCredits.MouseLeave:Connect(function()
	closeCredits.TextColor3 = Color3.fromRGB(255,255,255)
end)

openGui.MouseButton1Click:Connect(function()
	screen:TweenPosition(UDim2.new(0, 0,0, 0), "Out", "Quad", 0.5, true)
	openGui:TweenPosition(UDim2.new(-0.2, 0,0.444, 0), "Out", "Quad", 1, true)
	pop:Play()
end)

openGui.MouseEnter:Connect(function()
	openGui:TweenSize(UDim2.new(0, 131,0, 60), "Out", "Quad", 0.01, true)
end)

openGui.MouseLeave:Connect(function()
	openGui:TweenSize(UDim2.new(0, 111,0, 50), "In", "Quad", 0.01, true)
end)

Its quite long for something so simple but i only put spaces in between each event.
I put spaces because its super difficult to read without, it looks like this with no spaces:

local screen = script.Parent.Screen
local creditsMenu = script.Parent.CreditsMenu
local playButton = script.Parent.Screen.Play
local creditsButton = script.Parent.Screen.Credits
local closeCredits = script.Parent.CreditsMenu.CloseCredits
local openGui = script.Parent.OpenGui
local pop = game.Workspace.pop
playButton.MouseEnter:Connect(function()
	playButton:TweenSize(UDim2.new(0, 210,0, 60), "Out", "Quad", 0.01, true)
end)
playButton.MouseLeave:Connect(function()
	playButton:TweenSize(UDim2.new(0, 200,0, 50),"In", "Quad", 0.01,true)
end)
creditsButton.MouseEnter:Connect(function()
	creditsButton:TweenSize(UDim2.new(0, 210,0, 60), "Out", "Quad", 0.01, true)
end)
creditsButton.MouseLeave:Connect(function()
	creditsButton:TweenSize(UDim2.new(0, 200,0, 50),"In", "Quad", 0.01,true)
end)
playButton.MouseButton1Click:Connect(function()
	screen:TweenPosition(UDim2.new(0, 0,1, 0), "Out", "Quad", 0.5, true)
	openGui:TweenPosition(UDim2.new(0.011, 0,0.444, 0), "In", "Quad", 1, true)
	pop:Play()
end)
creditsButton.MouseButton1Click:Connect(function()
	creditsMenu:TweenPosition(UDim2.new(0.499, 0,0.5, 0), "In", "Quad", 0.5, true)
	screen:TweenPosition(UDim2.new(0, 0,1, 0), "Out", "Quad", 0.5, true)
	pop:Play()
end)
closeCredits.MouseButton1Click:Connect(function()
	creditsMenu:TweenPosition(UDim2.new(0.499, 0,1.5, 0), "Out", "Quad", 0.5, true)
	screen:TweenPosition(UDim2.new(0, 0,0, 0), "In", "Quad", 0.5, true)
	pop:Play()
end)
closeCredits.MouseEnter:Connect(function()
	closeCredits.TextColor3 = Color3.fromRGB(255,0,0)
end)
closeCredits.MouseLeave:Connect(function()
	closeCredits.TextColor3 = Color3.fromRGB(255,255,255)
end)
openGui.MouseButton1Click:Connect(function()
	screen:TweenPosition(UDim2.new(0, 0,0, 0), "Out", "Quad", 0.5, true)
	openGui:TweenPosition(UDim2.new(-0.2, 0,0.444, 0), "Out", "Quad", 1, true)
	pop:Play()end)
openGui.MouseEnter:Connect(function()
	openGui:TweenSize(UDim2.new(0, 131,0, 60), "Out", "Quad", 0.01, true)
end)
openGui.MouseLeave:Connect(function()
	openGui:TweenSize(UDim2.new(0, 111,0, 50), "In", "Quad", 0.01, true)
end)
1 Like