# EntityService

### Functions

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

Returns entities contained in the radius around the center position.

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

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

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

Spawns a [CreatureEntity](/scripting/bedwars-scripting/objects/entity/creatureentity.md) using a BedWars [CreatureType](/scripting/bedwars-scripting/types/creaturetype.md) model at the specified position. Use the optional team parameter with Skeletons or Ducks to set them to be allied with that [Team](/scripting/bedwars-scripting/objects/team.md). Use the returned [CreatureEntity](/scripting/bedwars-scripting/objects/entity/creatureentity.md) 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](/scripting/bedwars-scripting/objects/entity/imageentity.md)

Creates an [ImageEntity](/scripting/bedwars-scripting/objects/entity/imageentity.md) 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](/scripting/bedwars-scripting/objects/entity/imageentity.md) 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)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.easy.gg/scripting/bedwars-scripting/services/entityservice.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
