Studio Tips and Tricks I've Learned

Hi there! There may obviously be a few of these that you already knew, if not all. I’m not claiming to be a pro at all by posting this. I’m just wanting those out there that are struggling with a few annoying aspects of developing in Roblox Studio to be able to bypass those struggles like I wasn’t able to at first. So, without further ado, here are a few tips and tricks that I’ve learned in Roblox Studio.

1) CTRL + / to comment out sections of highlighted code.

2) Use a UIAspectRatioConstraint to keep your images square or go further with AutoScale Lite to preserve the aspect ratio of a GuiObject on all screen sizes.

3) If you don’t know what return does, LEARN IT! That was probably one of the biggest things holding me back as a scripter in the beginning. It will help you out tons if you understand that from the get-go.

4) When hovering over a model you can hold down ALT to select parts inside of it. It’s a good idea though to just avoid this when unnecessary (by using folders instead of models).

5) Get the Reclass plugin. It allows you to change an object’s class to something similar while intelligently preserving its properties.

6) Holding down CTRL while scaling items will scale that axis of the object equally on both sides instead of one. Also, hotkeys for selecting, moving, scaling, and rotating are much faster than clicking between them; 1, 2, 3, and 4 respectively.

7) A good way to solve bugs after you’ve tried extensively yourself, including asking a good AI, is the Unofficial Roblox server in their #development-help channel. If all else fails, I’ll post a detailed explanation of my problem on the DevForum. Doing these things will almost always solve your problems. If not, sleep on it, and hopefully it will come to you.

8) You can store multiple local variables on the same line by using commas such as in this example:

local var_1, var_2 = "blue", "purple"

9) When you want to replace lots of words/phrases that are the same with one new word or phrase, use the shortcut CTRL + F/CTRL + SHIFT + F. It’s called “Find and replace”. Very nice if you haven’t used it yet.

10) You can set boolean properties of instances to conditions (which are booleans themselves):

local pages
local tabs

for _, tab in tabs:GetChildren() do
  -- Given that each tab and designated page name are the same..

  tab.MouseButton1Down:Connect(function()
    for _, page in pages:GetChildren() do

      -- You can do this
      page.Visible = page.Name == tab.Name

      -- Instead of
      if page.Name == tab.Name then
        page.Visible = true
      else
        page.Visible = false
      end

    end
  end
end

11) And lastly viruses, oh boy have I had my fair share. If your game is literally freezing at the start and you have no idea what’s causing it, there’s probably a backdoor somewhere. A good way to find and remove these is by using the CTRL + SHIFT + F “Find and replace” tool mentioned earlier and look for suspicious keywords like getfenv or require (if they’re not yours). Another way to see right away if a free model script is suspicious is if you find something like this (found in the common boombox):

And yea that’s most of the stuff I can think of right now. Please let me know what you thought by replying to this topic, thanks!

22 Likes

wrong link i suggest pasting the server invite link also there are a lot of unnofficial roblox devolopment servers maybe add the fact that the link is of discord since for ppl who dont know about it it just shows a login page and once u make an account a no text channels msg

You can write everything on the same line, as Lua ignores whitespace during parsing.

local function f(x)return x+1 end print(f(1))print(f(2))

In what way is the first example more efficient? If there is any difference it should be less efficient since it will do an unnecessary test on the result of the and expression.

3 Likes

I’d imagine these tips would be useful to people who don’t know them, but I’d like to offer some constructive criticism. Particularly on tips 8 and 9.


local var_1, var_2 = "blue", "purple"

is not the same as

local var_1 = "blue"; var_2 = "purple"

In the first code snippet, both variables are local. In the second code snippet, only var_1 is local.
If you want to do something equivalent, you’d do this:

local var_1 = "blue"; local var_2 = "purple"

My second critique expands upon what Halalaluyafail3 was saying about abusing and.
While this works, it makes the code less readable. Not only that, it appears to be slightly less performant.

I did a naïve test because I was curious and using simple if statements seems to be ~60% faster.

function findTimeTaken(fun,loopAmount)
	local beginTime = os.clock()
	local testInput = true
	for i=1,loopAmount do
		fun(testInput)
		testInput = not testInput
	end
	print("Time taken: ",string.format("%f",os.clock()-beginTime))
end

local speed

local function functionA(on)
	speed = on and 16 or 0
end

-- instead of

local speed

local function functionB(on)
	if on then
		speed = 16
	else
		speed = 0
	end
end

findTimeTaken(functionA,10000000)
findTimeTaken(functionB,10000000)

Performance isn’t the issue here, since it’s basically negligible for most things. It just adds unnecessary complexity.

1 Like

I wasn’t saying they’re the same. Oh, I didn’t know that about the performance. I’ll be sure to update

1 Like

Alright, I’ll be sure to fix that. Thanks for letting me know

1 Like

For the white space part, yes I knew that but it looks more readable. But had no idea the condition part wasn’t more efficient. I just assumed less words = more efficient. I was clearly wrong lol

You don’t have to put parenthesis around a comparison operator, they are operators and can be used in any context where an operator can be used.

Example:

local x = 1
local y = 2
local z = x == y

So this

page.Visible = (page.Name == tab.Name)

doesn’t need the parenthesis and can be written without them.

page.Visible = page.Name == tab.Name
1 Like

Once again, I took readability into account; but thank you for the heads up.