Player
A player in this experience's world. Every method raises once the player has left; inside playerLeave and players.onLeave handlers the handle still works.
Fields
Methods
player:sendMessage(text: string)#Sends a chat message. Counts toward the limit of 20 messages and titles per player per second; going over raises.
player:title(title: string, subtitle: string?, fadeIn: number?, stay: number?, fadeOut: number?)#Shows a title and optional subtitle. Fades default to 0.5s in, 3.5s stay, 1s out. Counts toward the 20 messages per player per second limit.
player:clearTitle()#Removes the title on screen.
player:actionBar(text: string?, slot: string?, seconds: number?)#Puts text in a named action bar slot ("script" by default); every live slot of the player's is joined into one line. The text lasts seconds (default 3): call again to keep it up. nil text clears the slot.
player:sound(sound: string, volume: number?, pitch: number?)#Plays a sound key ("entity.experience_orb.pickup") only this player hears. Volume >= 0 (default 1), pitch 0.5..2 (default 1).
player:particle(particle: string, x: number, y: number, z: number, count: number?, dx: number?, dy: number?, dz: number?, speed: number?)#Shows particles only this player sees. count 1..1000 (default 1); dx/dy/dz are the random spread (default 0); speed defaults to 0.
player:tabList(header: string, footer: string)#Sets the tab list header and footer.
player:position() -> (number, number, number)#Returns the player's x, y, z (feet).
player:rotation() -> (number, number)#yaw, pitch in degrees
player:teleport(x: number, y: number, z: number, yaw: number?, pitch: number?)#Moves the player. A nil yaw or pitch keeps the current one.
player:velocity() -> (number, number, number)#blocks per second
player:setVelocity(x: number, y: number, z: number)#blocks per second
player:input() -> PlayerInput#Returns the movement keys held right now.
player:movementKeys() -> (boolean, boolean, boolean, boolean, boolean, boolean, boolean)#Like input, as seven booleans: forward, backward, left, right, jump, sneak, sprint.
Seats the player on an entity. Raises if that entity cannot carry a rider.
player:dismount()#Gets the player off whatever they ride.
player:setFlying(allowed: boolean, flying: boolean?)#Allows or forbids flight; flying (default false) starts them flying, only when allowed.
player:setInvisible(invisible: boolean)#Hides or shows the player to others.
player:give(item: string, count: number?) -> number#Gives count (1..2304, default 1) of an item. Returns how many fit; the rest is not given. how many fit
player:take(item: string, count: number?) -> number#Removes up to count (default 1) of an item. Returns how many were taken. how many were taken
player:count(item: string) -> number#Returns how many of an item the player carries in total.
player:has(item: string, count: number?) -> boolean#Whether the player carries at least count (default 1) of an item.
player:clear(item: string?)#Removes every stack of an item, or with nil empties the whole inventory, armour included.
player:held() -> (string?, number)#Returns the item key and count in the selected hotbar slot, or nil, 0 when it is empty.
player:slot(slot: number) -> (string?, number)#Returns the item key and count in an inventory slot (0..45; 0..8 is the hotbar), or nil, 0.
player:setSlot(slot: number, item: string?, count: number?)#Puts count (default 1) of an item in a slot (0..45). nil item empties it.
Returns the item key in a gear slot, or nil when it is empty.
player:health() -> number#in half-hearts
player:maxHealth() -> number#in half-hearts; 20 is ten hearts
player:setHealth(health: number)#Sets health in half-hearts, capped at maxHealth. Raises if negative.
player:heal(amount: number)#Adds health in half-hearts. Raises if negative.
player:damage(amount: number, kind: string?) -> boolean#Hurts the player by amount half-hearts, as damage type kind (a key, default "minecraft:generic"). Raises playerDamage on the way. Returns whether the hit landed.
player:kill()#Kills the player.
player:food() -> number#0..20
player:setFood(food: number)#Sets the hunger bar, 0..20. Raises outside that range.
player:effect(effect: string, seconds: number, amplifier: number?)#Applies a potion effect ("speed", "minecraft:jump_boost") for seconds (> 0). amplifier 0..255, default 0 (level I).
player:clearEffect(effect: string?)#Removes one effect, or every effect when nil.
player:hasEffect(effect: string) -> boolean#Whether the effect is active.
player:hasPermission(node: string) -> boolean#Whether the player has a permission node.
player:kick(reason: string?)#Disconnects the player from the server with an optional reason.