evasivedocs
Roblox scriptingLuau 0.748 · 24 guides · 385 API entries
Tutorials

Reading the game

Everything in a Roblox game is an object in one big tree: the game itself at the top, services under it, and the map, players and characters further down. This tutorial shows you how to walk that tree and read what you need.

How reading works here

evasive reads the game from outside. Each time you read a property, the value comes fresh from the running game. Nothing is cached, so a value is never stale, and reading it twice can give two different answers if the game changed in between.

Reads are cheap, but not free. A loop over a few hundred parts every frame is fine. Calling GetDescendants() on the whole workspace every frame is not.

Services

game:GetService(name) finds a service by its class name. These are the ones you will use most:

Luau
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local HttpService = game:GetService("HttpService")
local Lighting = game:GetService("Lighting")

Some games rename their services. GetService goes by class, so it still finds them. workspace is always the current place's Workspace.

Players

Luau
local Players = game:GetService("Players")
local me = Players.LocalPlayer

for _, player in ipairs(Players:GetPlayers()) do
    local team = player.Team and player.Team.Name or "no team"
    print(player.Name, player.DisplayName, player.UserId, team)
end

GetPlayers() includes you. Compare with player == me to skip yourself.

To check whether someone is on your team, compare the teams. In games without teams both are nil, so check that too:

Luau
local function isTeammate(player)
    local me = game:GetService("Players").LocalPlayer
    return player.Team ~= nil and player.Team == me.Team
end

Characters

A player's Character is a Model with the body parts and a Humanoid. It is nil while the player is dead or loading.

Luau
local function bodyOf(player)
    local character = player.Character
    if not character then
        return nil
    end
    local root = character:FindFirstChild("HumanoidRootPart")
    local head = character:FindFirstChild("Head")
    local humanoid = character:FindFirstChildOfClass("Humanoid")
    if root and head and humanoid then
        return { character = character, root = root, head = head, humanoid = humanoid }
    end
    return nil
end

local me = game:GetService("Players").LocalPlayer
local body = bodyOf(me)
if body then
    print("health", body.humanoid.Health, "of", body.humanoid.MaxHealth)
    print("walk speed", body.humanoid.WalkSpeed)
    print("head at", body.head.Position)
end

Humanoid gives you Health, MaxHealth, WalkSpeed, JumpPower and HipHeight to read.

Distance

Subtract two positions and take the length:

Luau
local Players = game:GetService("Players")
local me = Players.LocalPlayer

local function distanceTo(player)
    local mine = me.Character and me.Character:FindFirstChild("HumanoidRootPart")
    local theirs = player.Character and player.Character:FindFirstChild("HumanoidRootPart")
    if mine and theirs then
        return (theirs.Position - mine.Position).Magnitude
    end
    return nil
end

Distances are in studs. A standard character is about five studs tall.

Finding things

Method What it returns
FindFirstChild(name) The first child with that name, or nil
FindFirstChild(name, true) The same, but searches every level below
FindFirstChildOfClass(class) The first child of exactly that class
FindFirstChildWhichIsA(class) The first child that is that class or inherits from it
FindFirstAncestor(name) The nearest parent, grandparent and so on with that name
GetChildren() A list of the children
GetDescendants() A list of everything below, at every level
WaitForChild(name) Waits until a child with that name exists, then returns it
IsA(class) Whether the object is that class or inherits from it
IsDescendantOf(other) Whether the object is somewhere below other

You can also write workspace.Map to get a child called Map. That raises an error when there is no such child, so prefer FindFirstChild when you are not sure.

WaitForChild pauses your thread until the child appears. After five seconds it prints an "Infinite yield possible" warning but keeps waiting.

Searching the map

To find every part with a certain name, walk the descendants once and keep what you need. Big maps have tens of thousands of objects, so pause now and then:

Luau
local function findParts(name)
    local found = {}
    for i, object in ipairs(workspace:GetDescendants()) do
        if object.Name == name and object:IsA("BasePart") then
            table.insert(found, object)
        end
        if i % 2000 == 0 then
            task.wait()
        end
    end
    return found
end

local coins = findParts("Coin")
print("coins on the map:", #coins)

Do a search like this once (or every few seconds), then read the positions of the parts you found as often as you like.

Parts

Every part (BasePart and the classes under it) has these:

Luau
local root = game:GetService("Players").LocalPlayer.Character:FindFirstChild("HumanoidRootPart")

print(root.Position)       -- Vector3
print(root.CFrame)         -- position and rotation
print(root.Size)           -- Vector3
print(root.Velocity)       -- studs per second
print(root.Transparency, root.Color, root.Anchored, root.CanCollide)

CFrame.LookVector is the direction a part faces. A model's GetPivot() gives its position and rotation as one CFrame, and GetExtentsSize() the size of the box around all its parts.

Attributes

Many games store data in attributes:

Luau
local character = game:GetService("Players").LocalPlayer.Character
print(character:GetAttribute("Stamina"))
for name, value in pairs(character:GetAttributes()) do
    print(name, value)
end

GetAttribute returns nil for an attribute that does not exist.

Events

You do not have to poll for everything. These events fire on their own:

Luau
local Players = game:GetService("Players")
local names = {}

Players.PlayerAdded:Connect(function(player)
    names[player] = player.Name
    print(player.Name, "joined")
end)

Players.PlayerRemoving:Connect(function(player)
    print(names[player] or "someone", "left")
    names[player] = nil
end)

Players.LocalPlayer.CharacterAdded:Connect(function(character)
    print("respawned as", character:GetFullName())
end)

PlayerAdded only fires for players who join after you connect. Loop over GetPlayers() once at the start to handle the ones already there.

evasive watches for these changes about ten to twenty times a second, so an event can arrive a fraction of a second after it happened in game.

That also means PlayerRemoving and CharacterRemoving fire after the player or character is already gone. The object you get still works as a table key and still equals the one you saw before, but its properties read as empty. Store what you need (like the name) when it arrives, as the code above does.

Other things you can read

Object Useful members
game PlaceId, GameId, JobId, IsLoaded()
workspace.CurrentCamera CFrame, Position, FieldOfView, ViewportSize, WorldToViewportPoint(point)
Lighting ClockTime, Ambient, ExposureCompensation
A Model PrimaryPart, GetPivot(), GetExtentsSize()
A value object (IntValue, StringValue and so on) Value
A GUI object AbsolutePosition, AbsoluteSize, Visible, and Text on text objects
Players.LocalPlayer:GetMouse() X, Y (the cursor in the Roblox window)

getgamename() returns the game's title as players see it on the Roblox site. It asks Roblox's web API the first time, so it pauses your thread for a moment.