You are on page 1of 13

Faça login em Medium com o Google

Raphael Menezes
raphaelm@gmail.com

Roblox Code Automation with Lua


Continuar comoCode
Raphael

Templates in Roblox Studio with


Para criar a conta, AutoHotkey
o Google compartilhará seu
nome, endereço de e-mail e sua foto do perfil com o
SplitPainter · Follow app Medium. Consulte a Política de Privacidade e os
Termos de Serviço do app Medium.
Published in ROBLOX Academy
5 min read · Oct 16, 2017

Listen Share

Automation is key when developing software. That includes automating repetitive


tasks like building pipelines but also coding and typing. One of the most
productivity savers when coding are code templates and autocomplete.

Roblox Studio comes with autocomplete (which doesn’t work sometimes), but it
doesn’t have code templates. But fear not, you can create your own code templates
using text expanders.

AutoHotkey to the rescue


AutoHotkey is a very powerful free and open source Windows automation tool. It’s
been around for quite some time and is used worldwide by all kinds of IT
professionals (and non professionals as well). According to their website:

The ultimate automation scripting language for Windows. AutoHotkey is a free, open-
source scripting language for Windows that allows users to easily create small to complex
scripts for all kinds of tasks such as: form fillers, auto-clicking, macros, etc.

As a programmer myself, I’ve been using it practically since its launch in 2004 and I
can say that I can’t live without it.

Go ahead, download and install it: https://autohotkey.com/download/. Official docs:


https://autohotkey.com/docs/AutoHotkey.htm.

How to Create Expanding Words and Templates?


AutoHotkey has a feature called Hotstrings, which is what we are going to use. With
Hotstrings, you define a text abbreviation which you want to be replaced with
another word, phrase or even text with multiple lines. You can also simulate any
keystroke (example: {enter}{left 2}, to place an ENTER and move the caret two times
to the left).

Open Notepad or any other text editor and create a new file.

One of the most common lines in Roblox scripts is: local parent = script.Parent or
normally declared as local sp= script.Parent. How to create a template for this line?

:*:xsp::local sp = script.Parent`n

Whoa! What is this nonsense? Hold on! It is easier than it looks:

:*: - this is telling AutoHotkey that this is a Hotstring


xsp - this is our abbreviation
:: - this is a separator between the abbreviation and the output
local sp = script.Parent`n - is what is going to be replaced when we
type xsp. The backtick n (`n) means a new line.

Save the file and save it as roblox-templates.ahk. Double click to open it and execute
AutoHotkey in the background. You can see the file running in the AutoHotkey icon
in the system tray. You can pause and suspend the hotkeys anytime by right clicking
the icon.
Also anytime that you modify your .ahk file, you have to click “Reload This Script”
over there.

How to Use the Expansions?


Simply open Roblox Studio and type any of your abbreviations. In our case, let’s test
the one we just created. Type xsp in a Lua script. This is what happens:

Open in app Sign up Sign In

Of course you can modify the abbreviation to anything that you want, such as /sp,
localsp, scriptparent, etc.

Position the Caret Between Parenthesis


Say you have a template which places a method and then you want to type only the
parameters after the expansion. This means moving the caret into the parenthesis.
Call {left [amount to move]} to simulate the LEFT key keypress.

:*:xwfc:::WaitForChild(""){left 2}
How to Replace an Abbreviation if you are Already Inside Another Word?
If you tried the above example exactly in the way that I did, it probably didn’t work
for you, because spxwfc was typed and not xwfc. When you use :*, AutoHotkey
expects the abbreviation by itself, standalone.

To make it work inside an existing word, like the above example, add a ? after :*.
Example:

:*?:xwfc:::WaitForChild(""){left 2}

Now Anywhere I Type Something, AutoHotkey Replaces the Words!


With AutoHotkey and the command #IfWinActive, we can isolate abbreviations and
templates to run only in certain programs! In our case, we can isolate our templates
to Roblox Studio.

First, run AutoHotkey Window Spy to grab the application name: right click the
system tray icon -> Window Spy -> make Roblox Studio the active program and then
copy the line ahk_exe [Something], like I show here:
Now, in your .ahk script, place your templates inside a #IfWinActive return clause:

#IfWinActive, ahk_exe RobloxStudioBeta.exe


:*:xsp::local sp = script.Parent`n
:*?:xwfc:::WaitForChild(""){left 2}
return

Reload AutoHotkey (right click system tray -> reload this script) and you are ready to
go!

Additional Tips
Raw Templates
If your template has characters that conflict with AutoHotkey’s commands and
syntax, you can place them inside curly braces, specially colon (:). Example:

:*:xeq::tool.Equipped{:}connnect(){left}

Multi-Line Templates
You can use `n , {Enter} or Continuation Sections.

Sample Templates

#IfWinActive, ahk_exe RobloxStudioBeta.exe


:*:l;::local{Space}
:*:llf::local function{Space}
:*:localsp::local sp = script.Parent`n
:*:getreplicated::local ReplicatedStorage =
game:GetService("ReplicatedStorage")`n
:*:getscriptservice::local ServerScriptService =
game:GetService("ServerScriptService")`n
:*:getsstorage::local ServerStorage =
game:GetService("ServerStorage")`n
:*:getphysics::local PhysicsService =
game:GetService("PhysicsService")`n
:*:localtool::local tool = script.Parent`n
:*?:waitchild:::WaitForChild(""){left 2}
:*?:firstchild:::FindFirstChild(""){left 2}
:*:tooleq::tool.Equipped{:}connnect(){left}
:*:tooluneq::tool.Unequipped{:}connnect(){left}
:*:getservice::game:GetService(""){left 2}
:*?:econnect::{:}connect{(}{)}{left}
:*?:connectfn::{:}connect{(}function{(}{)}{Enter}{up}{End}{Left}
:*:mtuple::local tuple = {{}...{}}`n
:*:inew::Instance.new(""){left 2}
:*:v3new::Vector3.new(){left}
:*:cfnew::CFrame.new(){left}
:*:cfang::CFrame.Angles(){left}
:*:c3new::Color3.new(){left}
:*:gwork::game.Workspace
:*?:brickcolor::.BrickColor = BrickColor.new(""){left}
:*:mrand::math.random(){left}
:*:/delay::delay(, function{(}{)}{Enter}{up}^{left}^{right}^{right}
{left 2}
:*?:/cf::CFrame.
:*?:/v3::Vector3.
:*?:/p::Parent
:*?:gethumanoid::local humanoid =
player.Character{:}WaitForChild("Humanoid")`n
:*?:gettorso::local torso =
player.Character{:}WaitForChild("Torso")`n
:*:infwhile::while true do{Enter}
:*?:kids::{:}GetChildren()`n
:*:tins::table.insert(){left}
:*:trem::table.remove(){left}
return

But is it Safe?
If you are worried about AutoHotkey being a safe piece of software, check the
following links. The community speaks for itself.

The AutoHotkey Foundation


This document may be downloaded in PDF format here. The name AutoHotkey Foundation
LLC comes directly from the name of…
autohotkey.com

AutoHotkey - Wikipedia
AutoHotkey is a free, open-source custom scripting language for
Microsoft Windows, initially aimed at providing easy…
en.wikipedia.org

Its official forums have thousands of members and posts:

https://autohotkey.com/boards/

A Google search returns 3.8 million results, mostly tutorials, documentations and so
on:

https://www.google.com.br/search?q=autohotkey&oq=autoh&ie=UTF-8

Roblox Game Development Autohotkey Programming Lua

Follow

Written by SplitPainter
9 Followers · Editor for ROBLOX Academy
A software engineer and startup owner w/ 22 years of experience. Creating 3 #Roblox Games #robloxdev
#rbxdev I also paint traditionally. Roblox: SplitPainter

More from SplitPainter and ROBLOX Academy

SplitPainter in ROBLOX Academy

Monokai Syntax Highlighting Color Theme in Roblox Studio


Monokai is probably the most used color theme worldwide by all kinds of developers in all
kinds of editors and IDEs, due to its soothing…

1 min read · Oct 18, 2017

13

See all from SplitPainter

See all from ROBLOX Academy


Recommended from Medium

The PyCoach in Artificial Corner

You’re Using ChatGPT Wrong! Here’s How to Be Ahead of 99% of


ChatGPT Users
Master ChatGPT by learning prompt engineering.

· 7 min read · Mar 17

30K 527
Love Sharma in ByteByteGo System Design Alliance

System Design Blueprint: The Ultimate Guide


Developing a robust, scalable, and efficient system can be daunting. However, understanding
the key concepts and components can make the…

· 9 min read · Apr 20

6.9K 53

Lists

General Coding Knowledge


20 stories · 132 saves

It's never too late or early to start something


13 stories · 47 saves

Coding & Development


11 stories · 78 saves

Stories to Help You Grow as a Software Developer


19 stories · 212 saves
Jacob Bennett in Level Up Coding

Use Git like a senior engineer


Git is a powerful tool that feels great to use when you know how to use it.

· 4 min read · Nov 15, 2022

8.2K 82

The Coding Diaries in The Coding Diaries

Why Experienced Programmers Fail Coding Interviews


A friend of mine recently joined a FAANG company as an engineering manager, and found
themselves in the position of recruiting for…

· 5 min read · Nov 2, 2022

5.8K 119

Kristen Walters in Adventures In AI

5 Ways I’m Using AI to Make Money in 2023


These doubled my income last year

· 9 min read · Jul 19

17.8K 283
Dr. Derek Austin 🥳 in Better Programming

Why I Prefer Regular Merge Commits Over Squash Commits


I used to think squash commits were so cool, and then I had to use them all day, every day.
Here’s why you should avoid squash

· 5 min read · Sep 30, 2022

1.2K 54

See more recommendations

You might also like