# EntityService

### Functions

#### getNearbyEntities(center: [**Vector3**](https://create.roblox.com/docs/reference/engine/datatypes/Vector3), radius: number): [Entity](https://docs.easy.gg/scripting/bedwars-scripting/objects/entity)\[] | nil

Returns entities contained in the radius around the center position.

#### spawnKitEntity(kitType: [KitType](https://docs.easy.gg/scripting/bedwars-scripting/types/kittype), position: [**Vector3**](https://create.roblox.com/docs/reference/engine/datatypes/Vector3)): [KitEntity](https://docs.easy.gg/scripting/bedwars-scripting/objects/entity/kitentity) | nil

Spawns an entity using a BedWars [KitType](https://docs.easy.gg/scripting/bedwars-scripting/types/kittype) model at the specified position. Use the returned [KitEntity](https://docs.easy.gg/scripting/bedwars-scripting/objects/entity/kitentity) object to further configure the [KitEntity](https://docs.easy.gg/scripting/bedwars-scripting/objects/entity/kitentity).

Example usage:

```lua
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](https://docs.easy.gg/scripting/bedwars-scripting/types/creaturetype), position: [**Vector3**](https://create.roblox.com/docs/reference/engine/datatypes/Vector3), team: [Team](https://docs.easy.gg/scripting/bedwars-scripting/objects/team) | nil): [CreatureEntity](https://docs.easy.gg/scripting/bedwars-scripting/objects/entity/creatureentity) | nil

Spawns a [CreatureEntity](https://docs.easy.gg/scripting/bedwars-scripting/objects/entity/creatureentity) using a BedWars [CreatureType](https://docs.easy.gg/scripting/bedwars-scripting/types/creaturetype) model at the specified position. Use the optional team parameter with Skeletons or Ducks to set them to be allied with that [Team](https://docs.easy.gg/scripting/bedwars-scripting/objects/team). Use the returned [CreatureEntity](https://docs.easy.gg/scripting/bedwars-scripting/objects/entity/creatureentity) object to further configure the entity.

Example usage:

{% code fullWidth="false" %}

```lua
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)
```

{% endcode %}

#### spawnImageEntity(image: string, position: [**Vector3**](https://create.roblox.com/docs/reference/engine/datatypes/Vector3)): [ImageEntity](https://docs.easy.gg/scripting/bedwars-scripting/objects/entity/imageentity)

Creates an [ImageEntity](https://docs.easy.gg/scripting/bedwars-scripting/objects/entity/imageentity) using an image at the specified position. The string for the image parameter must be a [rbxassetid](https://create.roblox.com/docs/projects/assets). Use the returned [ImageEntity](https://docs.easy.gg/scripting/bedwars-scripting/objects/entity/imageentity) object to further configure the entity.

```lua
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)
```
