Skip to main content

Python

Python is a high-level, general-purpose programming language. It is known for its simplicity and readability. Python is a great language for beginners and experts alike. It is also the language of choice for many developers in the Roblox community.

Getting Started

Run

rcc install roblox-py # Run as administrator or sudo depending on the path you are planning to add it to

to install the Python compiler.

It will also request for a path to add the python bindings to, use the default path.

Why use Python?

Python is an excellent language for Roblox development, especially when it comes to backends. It is easy to learn and has a huge standard library (ported to Roblox). Many distributions of Python are also supported including:

  • Jupyter Notebooks (Markdown gets converted to comments)
  • Bython (Python with C/JS syntax)

Events

Events can easily be used like so:

@game.Players.PlayerAdded
def onPlayerAdded(player):
print(f"{player.Name} has joined the game")

Embedding Lua

You can embed Lua in Python like so:

"""[[lua]]
local x = 10
print(x)
"""

Indexs start at 0

Unlike Lua, all indexs start at 0 in Python. This is also true for roblox-py.

Lua

local myTable = {1,2,3}
print(myTable[1]) -- 1

Python

myTable = [1,2,3]
print(myTable[0]) # 1

Import

import game.ReplicatedStorage

is equal to

local ReplicatedStorage = game:GetService("ReplicatedStorage")

import game.ReplicatedStorage as RS

is equal to

local RS = game:GetService("ReplicatedStorage")

from services import ReplicatedStorage #as RS

is also valid.

Export

Exporting values is a bit different than in vanilla Python.

global myFunc # Since Python 'global' is useless when compiling to lua, this has been reused as an export identifier.

def myFunc():
print("Hello, World!")

will generate a

return {
["myFunc"] = myFunc,
}

at the end of the file.