• Studio

  • Studio API

  • Bots

  • Web API

  • Designer Resources

  • Host Resources

  • Globals

    GameClient

    Inherits from:

    The global client object provides access to client-side game context and is available in Client and ClientAndServer scripts. Inherits from Game, so all Game properties (Players, Info, PlayerCount, etc.) are also available.

    Use cases:

    • Accessing the local player (the player running this client)
    • Responding to player connections and disconnections from the client's perspective
    • Client-specific UI updates and interactions
    • Managing local player state and input

    Availability:

    • Client scripts: client is always available
    • ClientAndServer scripts: Check if client ~= nil or server == nil to determine if running on client

    Example usage:

    Properties

    FocusGained

    ClientOnly
    ReadOnly

    Event fired when the world becomes visible, for example if the user closes a full screen UI while still connected to the world.

    FocusLost

    ClientOnly
    ReadOnly

    Event fired when the world is no longer visible, for example if the user opens a full screen UI while still connected to the world.

    PlayerConnected

    ClientOnly
    ReadOnly

    Event triggered when a player connects to the game from the client's perspective. Fires for all players, including the local player and remote players.

    NOTE: This fires when a player connects, NOT when their avatar spawns. For avatar spawn events, use player.CharacterChanged event.

    Event Parameters: Player: The player who connected

    --!Type(Client)
    
    function self:ClientStart()
        client.PlayerConnected:Connect(function(player)
            print(player.name .. " connected!")
            
            -- Check if it's the local player
            if player == client.localPlayer then
                print("I connected!")
            else
                print("Another player connected")
            end
            
            -- Display welcome message
            print("Welcome " .. player.name .. " (ID: " .. player.user.id .. ")")
        end)
    end
    
    --!Type(ClientAndServer)
    
    -- Track players on both client and server
    function self:ClientStart()
        client.PlayerConnected:Connect(function(player)
            print("[CLIENT] Player connected: " .. player.name)
            -- Update UI for client
        end)
    end
    
    function self:ServerStart()
        server.PlayerConnected:Connect(function(player)
            print("[SERVER] Player connected: " .. player.name)
            -- Initialize server-side player data
        end)
    end
    

    PlayerDisconnected

    ClientOnly
    ReadOnly

    Event triggered when a player disconnects from the game from the client's perspective. Fires for all players, including remote players (but not typically for local player as the client stops running). Use this to clean up client-side resources or update UI when other players leave.

    Event Parameters: Player: The player who disconnected

    --!Type(Client)
    
    function self:ClientStart()
        client.PlayerDisconnected:Connect(function(player)
            print(player.name .. " disconnected!")
            
            -- Clean up client-side references
            print("Goodbye " .. player.name)
            
            -- Update player count UI (use scene.playerCount for current scene)
            print("Players in scene: " .. scene.playerCount)
        end)
    end
    
    --!Type(Client)
    
    -- Example: Track and display active players
    local playerList = {}
    
    function self:ClientStart()
        -- RECOMMENDED: Use scene.players for current scene
        for i, player in ipairs(scene.players) do
            playerList[player.user.id] = player.name
        end
        
        -- Track players joining the scene
        scene.PlayerJoined:Connect(function(scene, player)
            playerList[player.user.id] = player.name
            print("Added to scene: " .. player.name)
        end)
        
        -- Track players leaving the scene
        scene.PlayerLeft:Connect(function(scene, player)
            playerList[player.user.id] = nil
            print("Left scene: " .. player.name)
        end)
    end
    

    Reset

    ClientOnly
    ReadOnly

    Event that can be fired to reset the state of the client. If you are using the RTSCamera, firing this event will recenter the camera on the character.

    isMobilePlatform

    boolean
    ClientOnly
    ReadOnly

    Returns true if the client is running on a mobile platform (iOS, Android, etc.) Unlike checking the width and height for portrait mode, this includes tablets that are using the landscape layout.

    localPlayer

    ClientOnly
    ReadOnly

    Provides direct access to the local player on this client. This is the player instance representing the user running this specific client. Use this to access local player properties, character, or user information.

    --!Type(Client)
    
    function self:ClientStart()
        local me = client.localPlayer
        print("My name: " .. me.name)
        print("My user ID: " .. me.user.id)
        
        -- Access local player character
        if me.character ~= nil then
            print("My position: " .. tostring(me.character.Position))
        end
        
        -- Check if local player is a moderator
        if me.isModerator then
            print("I am a moderator!")
        end
    end
    

    mainCamera

    ClientOnly
    ReadOnly

    This property helps you obtain the main camera for the game client. It fetches the first active, enabled camera tagged as "MainCamera" in the scene. If no such camera is found, it returns nil.

    worldBounds

    ClientOnly
    ReadOnly

    Bounds of the world. It is calculated from the bounds of all of the active renderers.

    Updated 19 days ago

    PocketWorlds Icon

    © 2025 Pocket Worlds. All rights reserved.