Skip to main content
Version: latest - a1.58.x ⚖️

👩‍💻 Player

Players are Entities that represents the individual behind the mouse and keyboard. Players are spawned automatically when connected to the server.

👪Inheritance
This class shares methods and events from Base Entity.
🧑‍💻API Source
The methods, properties and events descriptions from this page are defined in our GitHub API Repository!

Authority

🟥 You cannot spawn or Destroy Players.

🎒 Examples

-- Spawns and possess a Character when a Player joins the server
Player.Subscribe("Spawn", function(player)
local new_char = Character(Vector(), Rotator(), "nanos-world::SK_Male")
player:Possess(new_char)
end)

-- Destroys the Character when the Player leaves the server
Player.Subscribe("Destroy", function(player)
local character = player:GetControlledCharacter()
if (character) then
character:Destroy()
end
end)

🗿 Static Functions

Inherited Entity Static Functions
Player inherits from Base Entity Class, sharing it's methods and functions:
Base Entityscripting-reference/classes/base-classes/Entity
ReturnsNameDescription
table of Base EntityGetAllReturns a table containing all Entities of the class this is called on
Base EntityGetByIndexReturns a specific Entity of this class at an index
integerGetCountReturns how many Entities of this class exist
table of tableGetInheritedClassesGets a list of all directly inherited classes from this Class created with the Inheriting System
iteratorGetPairsReturns an iterator with all Entities of this class to be used with pairs()
table or nilGetParentClassGets the parent class if this Class was created with the Inheriting System
tableInheritInherits this class with the Inheriting System
booleanIsChildOfGets if this Class is child of another class if this Class was created with the Inheriting System
functionSubscribeSubscribes to an Event for all entities of this Class
functionSubscribeRemoteSubscribes to a custom event called from server
UnsubscribeUnsubscribes all callbacks from this Event in this Class within this Package, or only the callback passed
This class doesn't have own static functions.

🦠 Functions

Inherited Entity Functions
Player inherits from Base Entity Class, sharing it's methods and functions:
Base Entityscripting-reference/classes/base-classes/Entity
ReturnsNameDescription
BroadcastRemoteEventCalls a custom remote event directly on this entity to all Players
CallRemoteEventCalls a custom remote event directly on this entity to a specific Player
CallRemoteEventCalls a custom remote event directly on this entity
DestroyDestroys this Entity
tableGetClassGets the class of this entity
integerGetIDGets the universal network ID of this Entity (same on both client and server)
anyGetValueGets a Value stored on this Entity at the given key
booleanIsARecursively checks if this entity is inherited from a Class
booleanIsValidReturns true if this Entity is valid (i.e. wasn't destroyed and points to a valid Entity)
SetValueSets a Value in this Entity
functionSubscribeSubscribes to an Event on this specific entity
functionSubscribeRemoteSubscribes to a custom event called from server on this specific entity
UnsubscribeUnsubscribes all callbacks from this Event in this Entity within this Package, or only the callback passed
ReturnsNameDescription
AttachCameraToAttaches the Player`s Camera to an Actor
BanBans the player from the server
ConnectRedirects the player to another server
stringGetAccountIconURLReturn a URL which can be used through WebUI and Widgets to display the Player's Steam Avatar (64x64)
stringGetAccountID
stringGetAccountName
floatGetCameraArmLength
VectorGetCameraLocation
RotatorGetCameraRotation
Character or nilGetControlledCharacter
integerGetDimensionGets this Player's dimension
stringGetIP
stringGetName
integerGetPing
stringGetSteamID
anyGetValue
integerGetVOIPChannel
VOIPSettingGetVOIPSetting
booleanIsHost
booleanIsLocalPlayer
KickKicks the player from the server
PossessMakes a Player to possess and control a Character
ResetCameraResets the Camera to default state (Unspectate and Detaches)
RotateCameraToSmoothly moves the Player's Camera Rotation
SetCameraArmLengthSets the Player's Camera Arm Length (Spring Arm length)
SetCameraLocationSets the Player's Camera Location (only works if not possessing any Character)
SetCameraRotationSets the Player's Camera Rotation
SetCameraSocketOffsetSets the Player's Camera Socket Offset (Spring Arm Offset)
SetManualCameraFadeTurns on camera fading at the given opacity
SetNameSets the player's name
SetVOIPChannelSets the VOIP Channel of this Player (will only communicate with other players in the same channel)
SetVOIPSettingSets the VOIP Settings of this Player
SetVOIPVolumeSets the VOIP Volume of this Player
SpectateSpectates other Player
StartCameraFadeDoes a camera fade to/from a solid color
StopCameraFadeStops camera fading.
TranslateCameraToSmoothly moves the Player's Camera Location (only works if not possessing any Character)
UnPossessRelease the Player from the Character

AttachCameraTo

Attaches the Player`s Camera to an Actor

my_player:AttachCameraTo(actor, socket_offset, blend_speed)
TypeParameterDefaultDescription
Base Actoractor
Vectorsocket_offset
floatblend_speed

Ban

Bans the player from the server

my_player:Ban(reason)
TypeParameterDefaultDescription
stringreason

Connect

Redirects the player to another server

my_player:Connect(IP, password?)
TypeParameterDefaultDescription
stringIP
stringpassword?Server password

GetAccountIconURL

Return a URL which can be used through WebUI and Widgets to display the Player's Steam Avatar (64x64)

— Returns string.

local ret = my_player:GetAccountIconURL()

GetAccountID

— Returns string.

local ret = my_player:GetAccountID()

GetAccountName

— Returns string.

local ret = my_player:GetAccountName()

GetCameraArmLength

— Returns float.

local ret = my_player:GetCameraArmLength(return_base?)
TypeParameterDefaultDescription
booleanreturn_base?falseWhether to return the current (false) or base (true) value. The base is the same value set by SetCameraArmLength().

See also SetCameraArmLength.


GetCameraLocation

— Returns Vector.

local ret = my_player:GetCameraLocation()

See also SetCameraLocation.


GetCameraRotation

— Returns Rotator.

local ret = my_player:GetCameraRotation()

See also SetCameraRotation.


GetControlledCharacter

— Returns Character or nil.

local ret = my_player:GetControlledCharacter()

GetDimension

Gets this Player's dimension

— Returns integer.

local ret = my_player:GetDimension()

GetIP

— Returns string.

local ret = my_player:GetIP()

GetName

— Returns string.

local ret = my_player:GetName()

See also SetName.


GetPing

— Returns integer.

local ret = my_player:GetPing()

GetSteamID

— Returns string.

local ret = my_player:GetSteamID()

GetValue

— Returns any.

local ret = my_player:GetValue(key, fallback)
TypeParameterDefaultDescription
stringkey
anyfallback

GetVOIPChannel

— Returns integer.

local ret = my_player:GetVOIPChannel()

See also SetVOIPChannel.


GetVOIPSetting

— Returns VOIPSetting.

local ret = my_player:GetVOIPSetting()

See also SetVOIPSetting.


IsHost

— Returns boolean.

local ret = my_player:IsHost()

IsLocalPlayer

— Returns boolean.

local ret = my_player:IsLocalPlayer()

Kick

Kicks the player from the server

my_player:Kick(reason)
TypeParameterDefaultDescription
stringreason

Possess

Makes a Player to possess and control a Character

my_player:Possess(new_character, blend_time?, exp?)
TypeParameterDefaultDescription
Characternew_character
floatblend_time?0
floatexp?0

ResetCamera

Resets the Camera to default state (Unspectate and Detaches)

my_player:ResetCamera()

RotateCameraTo

Smoothly moves the Player's Camera Rotation

my_player:RotateCameraTo(rotation, time, exp?)
TypeParameterDefaultDescription
Rotatorrotation
floattime
floatexp?0Exponential used to smooth interp, use 0 for linear movement

SetCameraArmLength

Sets the Player's Camera Arm Length (Spring Arm length)

my_player:SetCameraArmLength(length, force)
TypeParameterDefaultDescription
floatlength
booleanforceWhether to bypass interpolation and set the target to its value directly

See also GetCameraArmLength.


SetCameraLocation

Sets the Player's Camera Location (only works if not possessing any Character)

my_player:SetCameraLocation(location)
TypeParameterDefaultDescription
Vectorlocation

See also GetCameraLocation.


SetCameraRotation

Sets the Player's Camera Rotation

my_player:SetCameraRotation(rotation)
TypeParameterDefaultDescription
Rotatorrotation

See also GetCameraRotation.


SetCameraSocketOffset

Sets the Player's Camera Socket Offset (Spring Arm Offset)

my_player:SetCameraSocketOffset(socket_offset)
TypeParameterDefaultDescription
Vectorsocket_offset

SetManualCameraFade

Turns on camera fading at the given opacity. Does not auto-animate, allowing user to animate themselves. Call StopCameraFade to turn fading back off.

my_player:SetManualCameraFade(in_fade_amount, color, in_fade_audio)
TypeParameterDefaultDescription
floatin_fade_amountRange [0..1], where 0 is fully transparent and 1 is fully opaque solid color.
Colorcolor
booleanin_fade_audio

SetName

Sets the player's name

my_player:SetName(new_name)
TypeParameterDefaultDescription
stringnew_name

See also GetName.


SetVOIPChannel

Sets the VOIP Channel of this Player (will only communicate with other players in the same channel)

my_player:SetVOIPChannel(channel)
TypeParameterDefaultDescription
integerchannel

See also GetVOIPChannel.


SetVOIPSetting

Sets the VOIP Settings of this Player

my_player:SetVOIPSetting(setting)
TypeParameterDefaultDescription
VOIPSettingsetting

See also GetVOIPSetting.


SetVOIPVolume

Sets the VOIP Volume of this Player

my_player:SetVOIPVolume(volume)
TypeParameterDefaultDescription
floatvolume

Spectate

Spectates other Player

my_player:Spectate(player, blend_speed?)
TypeParameterDefaultDescription
Playerplayer
floatblend_speed?0

StartCameraFade

Does a camera fade to/from a solid color. Animates automatically

my_player:StartCameraFade(from_alpha, to_alpha, duration, to_color, should_fade_audio, hold_when_finished)
TypeParameterDefaultDescription
floatfrom_alphaAlpha at which to begin the fade. Range [0..1], where 0 is fully transparent and 1 is fully opaque solid color.
floatto_alphaAlpha at which to finish the fade.
floatdurationHow long the fade should take, in seconds.
Colorto_colorColor to fade to/from.
booleanshould_fade_audioTrue to fade audio volume along with the alpha of the solid color.
booleanhold_when_finishedTrue for fade to hold at the ToAlpha until explicitly stopped (e.g. with StopCameraFade)

StopCameraFade

Stops camera fading.

my_player:StopCameraFade()

TranslateCameraTo

Smoothly moves the Player's Camera Location (only works if not possessing any Character)

my_player:TranslateCameraTo(location, time, exp?)
TypeParameterDefaultDescription
Vectorlocation
floattime
floatexp?0Exponential used to smooth interp, use 0 for linear movement

UnPossess

Release the Player from the Character

my_player:UnPossess()

🚀 Events

Inherited Entity Events
Player inherits from Base Entity Class, sharing it's events:
Base Entityscripting-reference/classes/base-classes/Entity
NameDescription
ClassRegisterTriggered when a new Class is registered with the Inheriting System
DestroyTriggered when an Entity is destroyed
SpawnTriggered when an Entity is spawned/created
ValueChangeTriggered when an Entity has a value changed with :SetValue()
NameDescription
DimensionChangeTriggered when a Player changes it's dimension
PossessTrigerred when Player starts controlling a Character
ReadyTriggered when Player is ready (the client fully joined, loaded the map and all entities and is ready to play)
UnPossessA Character was released from the Player
VOIPWhen a Player starts/ends using VOIP

DimensionChange

Triggered when a Player changes it's dimension
Player.Subscribe("DimensionChange", function(self, old_dimension, new_dimension)
-- DimensionChange was called
end)
TypeArgumentDescription
Playerself
integerold_dimension
integernew_dimension

Possess

Trigerred when Player starts controlling a Character
Player.Subscribe("Possess", function(self, character)
-- Possess was called
end)
TypeArgumentDescription
Playerself
Charactercharacter

Ready

Triggered when Player is ready (the client fully joined, loaded the map and all entities and is ready to play)
Player.Subscribe("Ready", function(self)
-- Ready was called
end)
TypeArgumentDescription
Playerself

UnPossess

A Character was released from the Player
Player.Subscribe("UnPossess", function(self, character)
-- UnPossess was called
end)
TypeArgumentDescription
Playerself
Charactercharacter

VOIP

When a Player starts/ends using VOIP

When 'is_talking' is true, return false to prevent this voice stream from playing (on server will prevent for everyone, on client will prevent only for the client)
Player.Subscribe("VOIP", function(self, is_talking)
-- VOIP was called
end)
TypeArgumentDescription
Playerself
booleanis_talking