Comment on page
🪨

EntityService

Service for creating new entities.

Functions

getNearbyEntities(center: Vector3, radius: number): Entity[] | nil

Returns entities contained in the radius around the center position.

spawnKitEntity(kitType: KitType, position: Vector3): KitEntity | nil

Spawns an entity using a BedWars KitType model at the specified position. Use the returned KitEntity object to further configure the KitEntity.
Example usage:
Events.MatchStart(function(event)
-- Add a Barbarian Kit entity to the game when the match begins
local kit = EntityService.spawnKitEntity(KitType.BARBARIAN, BlockService.getAboveRandomBlock())
-- Give the kit entity a rageblade weapon
kit:setHandItem(ItemType.RAGEBLADE)
-- Gives the kit a set of Iron armor
kit:setArmor(ItemType.IRON_HELMET)
end)

spawnCreatureEntity(creatureType: CreatureType, position: Vector3, team: Team | nil): CreatureEntity | nil

Spawns a CreatureEntity using a BedWars CreatureType model at the specified position. Use the optional team parameter with Skeletons or Ducks to set them to be allied with that Team. Use the returned CreatureEntity object to further configure the entity.
Example usage:
Events.EntityDeath(function(event)
-- Only spawn a creature if the entity that died was a player
if (event.entity:getPlayer() == nil) then
return
end
-- Only spawn a creature if this was the final kill of the player
if not event.finalKill then
return
end
-- Only spawn a creature if there was a killer
if (event.killer == nil) then
return
end
-- Only spawn a creature if the killer was a player
if (event.killer:getPlayer() == nil) then
return
end
local team = TeamService.getTeam(event.killer:getPlayer())
-- Spawns a Skeleton creature allied with the killer's team
EntityService.spawnCreatureEntity(CreatureType.SKELETON, event.killer.getPosition(), team)
end)

spawnImageEntity(image: string, position: Vector3): ImageEntity

Creates an ImageEntity using an image at the specified position. The string for the image parameter must be a rbxassetid. Use the returned ImageEntity object to further configure the entity.
function chase(player, entity)
while task.wait(0.1) do
if not player:getEntity() then
continue
end
entity:moveTo(player:getEntity():getPosition())
end
end
Events.BlockPlace(function(event)
if (event.blockType == ItemType.SLIME_BLOCK) then
local entity = EntityService.spawnImageEntity("rbxassetid://11467634330", event.position + Vector3.new(0,4,0))
entity:setCustomName("Gloop")
task.spawn(function()
chase(event.player, entity)
end)
end
end)