variable to access the game in python, This is literarily the game variable in roblox.
ValidPlayers = ["builderman"]@py.Workspace.Spawn.ToucheddefonTouch(touch):print("Spawn has been touched by", touch.Name)@game.Players.PlayerAddeddefonPlrAdd(plr):if plr.Name in ValidPlayers:# The player is in our admin list, print admin joinedprint("Admin", plr.Name, "has joined the game!!")
The above code will do the following:
When a part in workspace called "Spawn" is touched print the touching parts name in the output
When a player joins and their name is in the ValidPlayers list that means they are a admin and output that
Compiled code:
This code generated may be outdated, code generated with newer versions of roblox-pyc should deliver better results
--// Compiled using roblox-pyc \-------------------------------------- BUILT IN -------------------------------local py, libs, builtin =unpack(require(game.ReplicatedStorage["roblox.pyc"])(script).py)local stringmeta = builtin.stringmetalocal list = builtin.listlocal str = builtin.strlocal id = builtin.idlocal int = builtin.intlocal operator_in = builtin.operator_inlocal min = builtin.min-----------------------------------------------------------------------------local ValidPlayers =list {stringmeta"builderman"}localfunctiononTouch(touch)print(stringmeta"Spawn has been touched by", touch.Name)endonTouch = py.Workspace.Spawn.Touched(onTouch)localfunctiononPlrAdd(plr)if (operator_in(plr.Name, ValidPlayers)) thenprint(stringmeta"Admin", plr.Name, stringmeta"has joined the game!!")endendonPlrAdd = py.Players.PlayerAdded(onPlrAdd)
stringmeta, list, dict are all functions used to add the Python API to lua objects.
Embedding lua
Sometimes you need to do something in Lua, inside of a python script! But how?
print("Python code")for i inrange(1,10):print("Python loop", i)
Thats python code, now let's add some lua code
print("Python code")
for i in range(10):
print("Python loop", i)
"""[[lua]]
-- As seen above this is not a multiline comment because of the [[lua]]for i =1, 10doprint(i)end-- We can still use python functions in lua this time without a problemfor i, v inrange(10) doprint(i)end
"""
This is the same script but I split it to 3 different code blocks for syntax highlighting