Skip to content

PlayerSpawner

Class ยท server and client scripts

PlayerSpawner controls how the server spawns and respawns characters for connected players. Access it through World.PlayerSpawner.

Example

-- Server script.
World.PlayerSpawner.AutoSpawn = false
World.PlayerSpawner.RespawnDelay = 3

CharacterPrefab

Property
CharacterPrefab: string

CharacterPrefab is the prefab name used when spawning a player's character.

Default "Character"

RespawnDelay

Property
RespawnDelay: number

RespawnDelay is the delay in seconds after a character dies before PlayerSpawner spawns a replacement while AutoSpawn is true.

Default 5

AutoSpawn

Property
AutoSpawn: boolean

AutoSpawn spawns a character when a player joins and respawns one after RespawnDelay seconds when the current character dies. Set it to false to call Spawn from scripts instead.

Default true

Spawn

MethodServer only
Spawn(player: Entity, options: PlayerSpawnOptions?) -> Entity

Spawn creates a new character for player, replaces any existing character bound to that player, and returns the spawned character entity.

Parameter Type Description
self PlayerSpawner World.PlayerSpawner.
player Entity Player entity to spawn a character for.
options PlayerSpawnOptions? Optional PlayerSpawnOptions choosing a spawn anchor entity (At) or prefab override (Prefab).

Returns The newly spawned character entity.

Example

-- Server script.
Component.User.Added:Connect(function(player: Entity)
    local pad = World.Find("SpawnPad")
    local character = World.PlayerSpawner:Spawn(player, { At = pad })
    print(character.Name)
end)