Skip to content

Player

The player wrapper provides access to a connected player. Players are obtained via mc.players(), world.players, or as event handler arguments.

Player extends Entity — all entity properties and methods are available on players. Only player-specific additions are listed here.

Metatable name: "player"

  • player.name (string) — Username. Read-only.
  • player.uuid (string) — UUID. Read-only.
  • player.displayName (string) — Read-only.
  • player.customName (string or nil) — Assign to set.
  • player.isOp (boolean) — Operator status. Read-only.
  • player.ping (number) — Latency in ms. Read-only.
  • player.isFlying (boolean) — Read-only.
  • player.selectedSlot (number) — Hotbar slot 0–8. Read-only.
  • player.food (number) — Assign to set.
  • player.saturation (number) — Read-only.
  • player.xpLevel (number) — Read-only.
  • player.xpProgress (number) — Progress to next level (0–1). Read-only.
  • player.gamemode (string) — "survival", "creative", "adventure", "spectator". Assign to change.
  • player.data (table) — Persistent per-player data. See Storage.

Entity methods inherited: damage(), raycast(), addEffect(), removeEffect(), hasEffect(), setOnFireFor(), readNbt(), writeNbt().

Sends a chat message.

  • text (string) — Message text
player:sendMessage("Hello!")

Sends an action bar message.

  • text (string) — Message text
player:sendActionBar("&eHotbar message")

player:sendTitle(title, subtitle?, fadeIn?, stay?, fadeOut?)

Section titled “player:sendTitle(title, subtitle?, fadeIn?, stay?, fadeOut?)”

Sends a title.

ParamTypeDefaultDescription
titlestringTitle text
subtitlestringSubtitle text
fadeInnumber10Fade-in ticks
staynumber70Stay ticks
fadeOutnumber20Fade-out ticks
player:sendTitle("&cWarning", "&7Danger zone", 10, 70, 20)

Teleports to a position.

  • world (World) — Target world
  • pos (table) — {x, y, z} position
player:teleport(mc.world("minecraft:overworld"), { x = 0, y = 64, z = 0 })

Restores health.

  • amount (number) — Health to restore
player:heal(20)

Kicks the player.

  • reason (string) — Kick message
player:kick("You have been kicked!")

Checks a permission node.

  • node (string) — Permission node
if player:hasPermission("myplugin.admin") then end

Plays a sound.

  • id (string) — Sound identifier
  • volume (number, default 1.0) — Volume
  • pitch (number, default 1.0) — Pitch
player:playSound("minecraft:entity.ender_dragon.growl", 1.0, 1.0)

Gives an item to the inventory.

player:give(mc.createItem("diamond", 1))

Sets an item in a slot.

  • slot (number) — Slot index
  • item (ItemStack or nil) — Item or nil to clear

Gets the item in a slot.

  • slot (number) — Slot index

Clears the inventory.

player:clear()

Executes a command as the player.

  • command (string) — Command string (no / prefix)
player:executeCommand("say Hello!")

Each player has a per-player sidebar using a local Scoreboard instance.

Creates or updates the sidebar. Auto-shows on first creation. Partial updates merge.

player.sidebar = {
title = "&6My Server",
lines = { "&aWelcome!", "", "&7Players: " .. mc.onlineCount }
}
player.sidebar = { title = "&6Updated Title" }
player.sidebar = { lines = { "Line 1", "Line 2" } }
player.sidebar = { visible = false }
player.sidebar = nil -- destroy

type: string

Current title. Assign to update (sends packet if visible).

type: table

Lines array (strings). Assign to replace all lines.

type: boolean

Whether shown. Read-only.

type: number

Number of lines. Read-only.

Sets a specific line (1‑indexed).

  • n (number) — Line index
  • text (string) — Line text

Shows the sidebar.

Hides the sidebar.

Destroys the sidebar permanently.

local sb = player.sidebar
sb.title = "Updated Title"
sb.lines = { "Line A", "Line B", "Line C" }
sb:setLine(2, "Modified Line B")
sb:hide() sb:show() sb:destroy()