# Game API

The game API exposes the Roblox DataModel hierarchy, camera control, mouse input, and part manipulation. It is split into sub-tables: `game`, `camera`, `input`, `part`, and `utility`.

> All examples use `snake_case`. Every function is also accessible in `camelCase` and `PascalCase` — the engine accepts all three. Pick one and stay consistent in your scripts.

***

### game global

`game` mirrors the Roblox DataModel. You can index it by service name or use `game.get_service`.

```lua
local ws           = game.workspace
local plrs         = game.players
local local_player = game.local_player
local place_id     = game.place_id
local game_id      = game.game_id
```

#### game.get\_service

```lua
local svc = game.get_service("ReplicatedStorage")
```

Supported direct properties: `workspace`, `players`, `lighting`, `local_player`, `place_id`, `game_id`, `replicated_storage`, `replicated_first`, `starter_gui`, `starter_pack`, `starter_player`, `teams`, `sound_service`, `chat`

***

### Instance methods

Any Instance returned by `game` or `entity` supports these methods:

```lua
instance:get_children()
instance:get_descendants()
instance:find_first_child(name)
instance:find_first_child(name, true)           -- recursive
instance:find_first_child_of_class(class)
instance:find_first_child_which_is_a(class)
instance:find_first_descendant(name)
instance:find_first_descendant_of_class(class)
instance:find_first_ancestor(name)
instance:find_first_ancestor_of_class(class)
instance:is_a(class_name)
instance:is_descendant_of(ancestor)
instance:is_ancestor_of(descendant)
```

#### Write methods

Instances also support direct write methods:

```lua
-- BasePart
instance:set_position(x, y, z)
instance:set_size(x, y, z)
instance:set_velocity(x, y, z)
instance:set_angular_velocity(x, y, z)
instance:set_transparency(value)
instance:set_can_collide(bool)
instance:set_anchored(bool)
instance:set_can_query(bool)
instance:set_can_touch(bool)

-- Humanoid
instance:set_health(value)
instance:set_max_health(value)
instance:set_walk_speed(value)
instance:set_jump_power(value)
instance:set_jump_height(value)
instance:set_state(state_id)
```

***

### Instance properties

All instances support property reads and writes via `__index` and `__newindex`. You can read or assign properties directly.

#### Common properties

| Property    | Type     | Access |
| ----------- | -------- | ------ |
| `Name`      | string   | read   |
| `ClassName` | string   | read   |
| `Parent`    | Instance | read   |
| `Address`   | number   | read   |

#### BasePart properties

Applies to Part, MeshPart, UnionOperation, WedgePart, SpawnLocation, TrussPart, Seat, VehicleSeat, CornerWedgePart.

| Property          | Type          | Access                     |
| ----------------- | ------------- | -------------------------- |
| `Position`        | Vector3       | read/write                 |
| `Size`            | Vector3       | read/write                 |
| `Velocity`        | Vector3       | read/write                 |
| `AngularVelocity` | Vector3       | read/write                 |
| `CFrame`          | Vector3       | read/write (position only) |
| `Rotation`        | table (3x3)   | read/write                 |
| `LookVector`      | Vector3       | read                       |
| `RightVector`     | Vector3       | read                       |
| `UpVector`        | Vector3       | read                       |
| `Color`           | table {R,G,B} | read                       |
| `Transparency`    | number        | read/write                 |
| `Reflectance`     | number        | read/write                 |
| `CanCollide`      | bool          | read/write                 |
| `Anchored`        | bool          | read/write                 |
| `CanQuery`        | bool          | read/write                 |
| `CanTouch`        | bool          | read/write                 |
| `CastShadow`      | bool          | read/write                 |
| `Locked`          | bool          | read/write                 |
| `Massless`        | bool          | read/write                 |
| `Shape`           | number        | read                       |

```lua
local char = game.local_player.character
local head = char:find_first_child("Head")
if head then
    print("Position: " .. tostring(head.position))
    head.transparency = 0.5
    head.can_collide = false
    head.anchored = true
    head.reflectance = 1.0
    head.cast_shadow = false
end
```

#### Humanoid properties

| Property                | Type     | Access     |
| ----------------------- | -------- | ---------- |
| `Health`                | number   | read/write |
| `MaxHealth`             | number   | read/write |
| `WalkSpeed`             | number   | read/write |
| `JumpPower`             | number   | read/write |
| `JumpHeight`            | number   | read/write |
| `HipHeight`             | number   | read/write |
| `MaxSlopeAngle`         | number   | read/write |
| `State`                 | number   | read/write |
| `StateName`             | string   | read       |
| `IsAlive`               | bool     | read       |
| `IsDead`                | bool     | read       |
| `Sit`                   | bool     | read/write |
| `Jump`                  | bool     | read/write |
| `PlatformStand`         | bool     | read/write |
| `AutoRotate`            | bool     | read/write |
| `AutoJumpEnabled`       | bool     | read/write |
| `UseJumpPower`          | bool     | read/write |
| `RequiresNeck`          | bool     | read/write |
| `BreakJointsOnDeath`    | bool     | read/write |
| `EvaluateStateMachine`  | bool     | read/write |
| `IsWalking`             | bool     | read       |
| `WalkspeedCheck`        | number   | read/write |
| `WalkTimer`             | number   | read       |
| `MoveDirection`         | Vector3  | read       |
| `CameraOffset`          | Vector3  | read/write |
| `TargetPoint`           | Vector3  | read       |
| `RigType`               | number   | read       |
| `FloorMaterial`         | number   | read       |
| `DisplayDistanceType`   | number   | read/write |
| `HealthDisplayDistance` | number   | read/write |
| `HealthDisplayType`     | number   | read/write |
| `NameDisplayDistance`   | number   | read/write |
| `NameOcclusion`         | number   | read/write |
| `DisplayName`           | string   | read       |
| `SeatPart`              | Instance | read       |
| `HumanoidRootPart`      | Instance | read       |

```lua
local char = game.local_player.character
local hum = char:find_first_child("Humanoid")
if hum then
    hum.walk_speed = 50
    hum.jump_power = 100
    hum.state = 6  -- Flying
    hum.auto_rotate = false
    hum.sit = false
    print("State: " .. hum.state_name)
    print("Speed: " .. hum.walk_speed)
end
```

#### Player properties

| Property                | Type     | Access     |
| ----------------------- | -------- | ---------- |
| `Character`             | Instance | read       |
| `UserId`                | number   | read       |
| `DisplayName`           | string   | read       |
| `Team`                  | Instance | read       |
| `AccountAge`            | number   | read       |
| `CameraMode`            | number   | read/write |
| `MaxZoomDistance`       | number   | read/write |
| `MinZoomDistance`       | number   | read/write |
| `HealthDisplayDistance` | number   | read/write |
| `NameDisplayDistance`   | number   | read/write |

```lua
local lp = game.local_player
print("Account age: " .. lp.account_age .. " days")
lp.camera_mode = 1          -- LockFirstPerson
lp.max_zoom_distance = 0.5  -- force first person
```

#### Camera properties

| Property              | Type     | Access     |
| --------------------- | -------- | ---------- |
| `Position` / `CFrame` | Vector3  | read       |
| `FieldOfView`         | number   | read/write |
| `LookVector`          | Vector3  | read       |
| `CameraType`          | number   | read/write |
| `CameraSubject`       | Instance | read       |

```lua
local ws = game.workspace
local cam = ws:find_first_child_of_class("Camera")
if cam then
    print("FOV: " .. cam.field_of_view)
    print("Type: " .. cam.camera_type)
    cam.field_of_view = 90
    cam.camera_type = 0  -- Custom
end
```

#### Model properties

| Property      | Type     | Access |
| ------------- | -------- | ------ |
| `PrimaryPart` | Instance | read   |
| `Scale`       | number   | read   |

#### Tool properties

| Property               | Type | Access     |
| ---------------------- | ---- | ---------- |
| `CanBeDropped`         | bool | read/write |
| `Enabled`              | bool | read/write |
| `ManualActivationOnly` | bool | read/write |
| `RequiresHandle`       | bool | read/write |

```lua
local char = game.local_player.character
local tool = char:find_first_child_of_class("Tool")
if tool then
    tool.can_be_dropped = false
    tool.enabled = true
    print("Tool: " .. tool.name)
end
```

#### Sound properties

| Property             | Type   | Access     |
| -------------------- | ------ | ---------- |
| `Volume`             | number | read/write |
| `PlaybackSpeed`      | number | read/write |
| `Looped`             | bool   | read/write |
| `Playing`            | bool   | read/write |
| `RollOffMinDistance` | number | read/write |
| `RollOffMaxDistance` | number | read/write |

```lua
-- mute all sounds under workspace
local sounds = game.workspace:get_descendants()
for _, inst in ipairs(sounds) do
    if inst.class_name == "Sound" then
        inst.volume = 0
    end
end
```

#### ProximityPrompt properties

| Property                | Type   | Access     |
| ----------------------- | ------ | ---------- |
| `Enabled`               | bool   | read/write |
| `MaxActivationDistance` | number | read/write |
| `HoldDuration`          | number | read/write |
| `KeyCode`               | number | read/write |
| `RequiresLineOfSight`   | bool   | read/write |

```lua
-- make all prompts instant and long range
local descs = game.workspace:get_descendants()
for _, inst in ipairs(descs) do
    if inst.class_name == "ProximityPrompt" then
        inst.hold_duration = 0
        inst.max_activation_distance = 1000
        inst.requires_line_of_sight = false
    end
end
```

#### Seat properties

| Property   | Type     | Access |
| ---------- | -------- | ------ |
| `Occupant` | Instance | read   |

#### VehicleSeat properties

| Property    | Type   | Access     |
| ----------- | ------ | ---------- |
| `MaxSpeed`  | number | read/write |
| `Steer`     | number | read       |
| `Throttle`  | number | read       |
| `Torque`    | number | read/write |
| `TurnSpeed` | number | read/write |

```lua
local seat = game.workspace:find_first_child("VehicleSeat", true)
if seat then
    seat.max_speed = 200
    seat.torque = 50000
    print("Steer: " .. seat.steer)
    print("Throttle: " .. seat.throttle)
end
```

#### ScreenGui properties

| Property  | Type | Access     |
| --------- | ---- | ---------- |
| `Enabled` | bool | read/write |

#### Workspace properties

| Property              | Type     | Access     |
| --------------------- | -------- | ---------- |
| `Gravity`             | number   | read/write |
| `Terrain`             | Instance | read       |
| `DistributedGameTime` | number   | read       |

#### Lighting properties

| Property                   | Type            | Access     |
| -------------------------- | --------------- | ---------- |
| `Brightness`               | number          | read/write |
| `ExposureCompensation`     | number          | read/write |
| `FogStart`                 | number          | read/write |
| `FogEnd`                   | number          | read/write |
| `EnvironmentDiffuseScale`  | number          | read/write |
| `EnvironmentSpecularScale` | number          | read/write |
| `ClockTime`                | number          | read/write |
| `GeographicLatitude`       | number          | read/write |
| `GlobalShadows`            | bool            | read/write |
| `Ambient`                  | table {r,g,b,a} | read/write |
| `OutdoorAmbient`           | table {r,g,b,a} | read/write |
| `FogColor`                 | table {r,g,b,a} | read/write |

```lua
local lit = game.lighting
lit.clock_time = 12.0          -- set to noon
lit.brightness = 2.0
lit.fog_start = 0
lit.fog_end = 1000
lit.global_shadows = false
lit.geographic_latitude = 0
```

#### Terrain properties

| Property            | Type            | Access     |
| ------------------- | --------------- | ---------- |
| `GrassLength`       | number          | read/write |
| `WaterTransparency` | number          | read/write |
| `WaterReflectance`  | number          | read/write |
| `WaterWaveSize`     | number          | read/write |
| `WaterWaveSpeed`    | number          | read/write |
| `WaterColor`        | table {r,g,b,a} | read/write |

#### GuiObject properties

Applies to Frame, TextLabel, TextButton, TextBox, ImageLabel, ImageButton, ScrollingFrame.

| Property           | Type          | Access |
| ------------------ | ------------- | ------ |
| `Visible`          | bool          | read   |
| `Rotation`         | number        | read   |
| `LayoutOrder`      | number        | read   |
| `Position`         | table         | read   |
| `Size`             | table         | read   |
| `BackgroundColor3` | table {R,G,B} | read   |

#### TextLabel / TextButton / TextBox properties

| Property     | Type          | Access |
| ------------ | ------------- | ------ |
| `Text`       | string        | read   |
| `RichText`   | bool          | read   |
| `TextColor3` | table {R,G,B} | read   |

#### Value properties

IntValue, NumberValue, BoolValue, StringValue, ObjectValue, Vector3Value, CFrameValue all support `Value` for both read and write.

```lua
local coins = game.replicated_storage:find_first_child("Coins")
if coins then
    print("Coins: " .. coins.value)
    coins.value = 999
end
```

***

### Humanoid States

The `State` property uses a numeric enum. Use `StateName` for a readable string.

| Value | Name              |
| ----- | ----------------- |
| 0     | FallingDown       |
| 1     | Ragdoll           |
| 2     | GettingUp         |
| 3     | Jumping           |
| 4     | Swimming          |
| 5     | Freefall          |
| 6     | Flying            |
| 7     | Landed            |
| 8     | Running           |
| 10    | RunningNoPhysics  |
| 11    | StrafingNoPhysics |
| 12    | Climbing          |
| 13    | Seated            |
| 14    | PlatformStanding  |
| 15    | Dead              |
| 16    | Physics           |
| 18    | None              |

***

### Vector3

```lua
local v = Vector3.new(x, y, z)
```

Properties: `x`, `y`, `z`, `magnitude`, `unit`

Methods:

```lua
v:dot(other)        -- returns number
v:cross(other)      -- returns Vector3
v:lerp(other, t)    -- returns Vector3
```

Operators: `+`, `-`, `*`, `/`, unary `-`, `==`, `#` (returns magnitude)

```lua
local a = Vector3.new(1, 0, 0)
local b = Vector3.new(0, 1, 0)
local c = a + b
local d = a * 5
local len = #a
```

***

### camera API

```lua
local pos  = camera.get_position()     -- returns Vector3
local look = camera.get_look_vector()  -- returns Vector3
local fov  = camera.get_fov()          -- returns number

camera.set_fov(90)

camera.look_at(target_vec3)            -- snap camera to target
camera.look_at(target_vec3, 10)        -- smooth interpolation
camera.look_at(x, y, z)               -- raw numbers
```

Example: draw a tracer line to each player:

```lua
function on_frame()
    local w, h = utility.get_screen_size()
    local players = entity.get_players()

    for _, p in ipairs(players) do
        if p.is_local or not p.is_alive then goto continue end

        local sx, sy, visible = draw.world_to_screen(
            p.head_position.x,
            p.head_position.y,
            p.head_position.z
        )
        if visible then
            draw.line(w / 2, h, sx, sy, {1, 0.3, 0.3, 1})
        end

        ::continue::
    end
end
```

***

### input API

```lua
input.is_key_down(vk_code)    -- returns boolean
input.get_screen_center()     -- returns x, y
input.move_mouse(dx, dy)      -- relative mouse movement in pixels
```

`input.move_mouse` moves the cursor by `dx` pixels horizontally and `dy` pixels vertically relative to its current position. Uses SendInput with MOUSEEVENTF\_MOVE.

```lua
input.move_mouse(10, 0)    -- move right 10px
input.move_mouse(-5, -5)   -- move up-left
```

Example: aimbot step toward nearest player:

```lua
function on_frame()
    if not input.is_key_down(0x02) then return end

    local players = entity.get_players()
    local cx, cy = input.get_screen_center()
    local best_x, best_y = nil, nil
    local closest_dist = 150

    for _, p in ipairs(players) do
        if p.is_local or not p.is_alive then goto continue end

        local sx, sy, visible = draw.world_to_screen(
            p.head_position.x,
            p.head_position.y,
            p.head_position.z
        )
        if not visible then goto continue end

        local dist = math.sqrt((sx - cx)^2 + (sy - cy)^2)
        if dist < closest_dist then
            closest_dist = dist
            best_x, best_y = sx, sy
        end

        ::continue::
    end

    if best_x then
        local speed = 0.15
        local dx = (best_x - cx) * speed
        local dy = (best_y - cy) * speed
        input.move_mouse(math.floor(dx), math.floor(dy))
    end
end
```

Common VK codes: `0x01` (LMB), `0x02` (RMB), `0x04` (MMB), `0x10` (Shift), `0x11` (Ctrl), `0x12` (Alt), `0x20` (Space), `0x1B` (Escape)

***

### part API

Directly writes game state to part properties via memory. These are method-style calls that take an instance as the first argument.

```lua
part.set_position(instance, x, y, z)
part.set_size(instance, x, y, z)
part.set_velocity(instance, x, y, z)
part.set_angular_velocity(instance, x, y, z)
part.set_transparency(instance, value)
part.set_can_collide(instance, bool)
part.set_anchored(instance, bool)
part.set_can_query(instance, bool)
part.set_can_touch(instance, bool)
```

```lua
local root = game.local_player.character:find_first_child("HumanoidRootPart")
if root then
    part.set_velocity(root, 0, 100, 0)   -- launch upward
    part.set_anchored(root, true)         -- freeze in place
    part.set_can_collide(root, false)     -- noclip
end
```

***

### utility (instance) API

```lua
utility.is_valid(instance)              -- returns boolean
utility.clear_cache()                   -- clears internal name/class caches
utility.invalidate_instance(instance)   -- removes one instance from cache
```

Use `utility.is_valid` before reading from instances you obtained several frames ago.

```lua
function on_frame()
    local inst = get_some_instance()
    if not utility.is_valid(inst) then return end
    print(inst.name)
end
```

***

### Examples

#### Noclip

```lua
function on_frame()
    if not input.is_key_down(0x11) then return end  -- hold Ctrl

    local char = game.local_player.character
    if not char then return end

    local parts = char:get_children()
    for _, p in ipairs(parts) do
        if p:is_a("BasePart") then
            p.can_collide = false
        end
    end
end
```

#### Speed hack with anti-cheat mirror

```lua
local char = game.local_player.character
local hum = char:find_first_child("Humanoid")
if hum then
    local speed = 100
    hum.walk_speed = speed
    hum.walkspeed_check = speed  -- mirror for anti-cheat
end
```

#### Force fly state

```lua
local char = game.local_player.character
local hum = char:find_first_child("Humanoid")
if hum then
    hum.state = 6  -- Flying
    print("Now flying: " .. hum.state_name)
end
```

#### Disable all proximity prompts

```lua
local descs = game.workspace:get_descendants()
for _, inst in ipairs(descs) do
    if inst.class_name == "ProximityPrompt" then
        inst.enabled = false
    end
end
```

#### Fullbright

```lua
local lit = game.lighting
lit.brightness = 2
lit.clock_time = 14
lit.fog_end = 100000
lit.global_shadows = false
lit.ambient = {1, 1, 1}
lit.outdoor_ambient = {1, 1, 1}
```

#### Mute game audio

```lua
local descs = game.workspace:get_descendants()
for _, inst in ipairs(descs) do
    if inst.class_name == "Sound" then
        inst.volume = 0
        inst.playing = false
    end
end
```

#### Lock first person

```lua
local lp = game.local_player
lp.camera_mode = 1
lp.min_zoom_distance = 0.5
lp.max_zoom_distance = 0.5
```

#### Teleport to position

```lua
local root = game.local_player.character:find_first_child("HumanoidRootPart")
if root then
    root.position = Vector3.new(0, 100, 0)
end
```

#### Walk through walls (disable collision on all parts in character)

```lua
function on_frame()
    local char = game.local_player.character
    if not char then return end

    for _, child in ipairs(char:get_children()) do
        if child:is_a("BasePart") then
            child.can_collide = false
            child.can_query = false
        end
    end
end
```

***

### API Reference

| Function                                   | Returns  | Description               |
| ------------------------------------------ | -------- | ------------------------- |
| `game.workspace`                           | Instance | Workspace service         |
| `game.players`                             | Instance | Players service           |
| `game.lighting`                            | Instance | Lighting service          |
| `game.local_player`                        | Instance | Local player              |
| `game.place_id`                            | number   | Current place ID          |
| `game.game_id`                             | number   | Current game ID           |
| `game.get_service(name)`                   | Instance | Get any service by name   |
| `camera.get_position()`                    | Vector3  | Camera world position     |
| `camera.get_look_vector()`                 | Vector3  | Camera forward direction  |
| `camera.get_fov()`                         | number   | Current field of view     |
| `camera.set_fov(value)`                    | bool     | Set field of view         |
| `camera.look_at(target, smooth?)`          | bool     | Point camera at target    |
| `input.is_key_down(vk)`                    | bool     | Check if key is held      |
| `input.get_screen_center()`                | x, y     | Screen center coordinates |
| `input.move_mouse(dx, dy)`                 | -        | Relative mouse movement   |
| `part.set_position(inst, x, y, z)`         | -        | Set part position         |
| `part.set_size(inst, x, y, z)`             | -        | Set part size             |
| `part.set_velocity(inst, x, y, z)`         | -        | Set linear velocity       |
| `part.set_angular_velocity(inst, x, y, z)` | -        | Set angular velocity      |
| `part.set_transparency(inst, v)`           | -        | Set transparency          |
| `part.set_can_collide(inst, b)`            | -        | Set collision             |
| `part.set_anchored(inst, b)`               | -        | Set anchored              |
| `part.set_can_query(inst, b)`              | -        | Set raycast queryable     |
| `part.set_can_touch(inst, b)`              | -        | Set touch events          |
| `utility.is_valid(inst)`                   | bool     | Check instance validity   |
| `utility.clear_cache()`                    | bool     | Clear all caches          |
| `utility.invalidate_instance(inst)`        | -        | Clear one from cache      |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://project-vector-1.gitbook.io/vector-lua-engine/api/game-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
