Skip to main content

Players (client)

The client-only functions for finding players: the local player's handles from the World table, and the Players table, which controls the name tags drawn above players. For what you can do with the handles these functions return, see Player and Player (client).

Available on: Client

See also: Players

Functions​

World.LocalClient()​

Returns the PlayerHandle of the local player (the player running this client), or nil before this client has been accepted by the server.

Parameters: none

Returns

TypeDescription
PlayerHandle or nilthe local player's connection

Example

local me = World.LocalClient()

if me and me:HasAcl(AclLevel.Admin) then
print("you are an admin on this server")
end

World.LocalPlayer()​

Returns the local player's character as a plain ObjectHandle, or nil while the local player has no character (before it has spawned). Call :AsPlayer() on it to use the PlayerObjectHandle methods. For actions that only the local player can do, see Local.

Parameters: none

Returns

TypeDescription
ObjectHandle or nilthe local player's character

Example

Cmd.Add("where", function()
local obj = World.LocalPlayer()

if not obj then
return
end

local player = obj:AsPlayer()
local vehicle = player:GetVehicle()

print("position: " .. tostring(player:GetPosition()))
print(vehicle and ("in vehicle " .. vehicle:GetId()) or "on foot")
end)

Players.SetTagsEnabled(enabled)​

Shows or hides the name tags drawn above other players' heads. The setting applies to the whole client, not just the calling resource: it stays as set after the resource stops, until a script changes it again. Name tags are shown by default.

Parameters

NameTypeDescription
enabledbooleantrue to show name tags, false to hide them

Returns: nothing

Example

-- hide name tags during a hide-and-seek round, the server tells clients when it starts and ends
Net.AddEvent("HideAndSeek", function(active)
Players.SetTagsEnabled(not active)
end)

Players.AreTagsEnabled()​

Returns whether the name tags above players are currently shown.

Parameters: none

Returns

TypeDescription
booleantrue if name tags are shown

Example

Cmd.Add("tags", function()
Players.SetTagsEnabled(not Players.AreTagsEnabled())
print("name tags " .. (Players.AreTagsEnabled() and "on" or "off"))
end)