Type@ember/types
types.Entity
An entity a script spawned. Calls other than alive raise once it is removed.
Signals
entity.attacked: types.Signal<types.EntityClickEvent>A player hit the entity. A display fires only if it was spawned with a hitbox, and a model mob only if its content.mob declares one.
entity.clicked: types.Signal<types.EntityClickEvent>A player right-clicked the entity. A display fires only if it was spawned with a hitbox, and a model mob only if its content.mob declares one.
Fields
Methods
entity:follow(target: types.Entity, options: types.FollowOptions?)entity:follow(target: types.Player, options: types.FollowOptions?)The host moves this entity toward the target plus offset while the target moves away, and stops when the target is removed or leaves. Following again replaces the target.
local entities = require("@ember/entities")
local players = require("@ember/players")
local types = require("@ember/types")
-- A pet that trails each player. The host moves it, so no script runs per tick. It stops following
-- when the player leaves, but stays in the world, so remove it then.
local pets: { [string]: types.Entity } = {}
players.joined:connect(function(player)
local pet = entities.item({ at = player.position, item = "minecraft:cookie", billboard = "center" })
pet:follow(player, { offset = vector.create(1, 1.5, 0), speed = 6 })
pets[player.id] = pet
end)
players.left:connect(function(player)
local pet = pets[player.id]
if pet then
pet:remove()
pets[player.id] = nil
end
end)entity:remove()Removes it from the world; its handle goes stale.
entity:unfollow()Stops following; it stays where it is.