# BlockService

Example usage:

```lua
-- Replace block beneath all players with diamond blocks
while (task.wait(0)) do
    -- Loop over all players
    for i, player in pairs(PlayerService.getPlayers()) do
        -- Get player's entity
        local entity = player:getEntity()
        if (not entity) then
            continue
        end

        -- Get block beneath player
        local positionBeneath = entity:getPosition() - Vector3.new(0, 5, 0)
        local blockBeneath = BlockService.getBlockAt(positionBeneath)
        if blockBeneath then
            -- If block beneath exists then destroy it and place diamond block
            BlockService.destroyBlock(positionBeneath)
            BlockService.placeBlock(ItemType.DIAMOND_BLOCK, positionBeneath)
        end
    end
end
```

### Functions

#### placeBlock(blockType: [ItemType](https://docs.easy.gg/scripting/bedwars-scripting/services/broken-reference), position: [Vector3](https://create.roblox.com/docs/reference/engine/datatypes/Vector3)): bool

Placed a block at position. Returns true if block was placed.

#### getBlockAt(position: [Vector3](https://create.roblox.com/docs/reference/engine/datatypes/Vector3)): [Block](https://docs.easy.gg/scripting/bedwars-scripting/objects/block) | nil

Returns the block at the given position. Will return nil if no block exists at the position.

#### getAboveRandomBlock(aboveBlockTypes: [ItemType](https://docs.easy.gg/scripting/bedwars-scripting/services/broken-reference)\[] | nil): [Vector3](https://create.roblox.com/docs/reference/engine/datatypes/Vector3)

Returns a random position above a block. Can optionally specify a set of `aboveBlockTypes` to get a position only above a block of those types.

#### destroyBlock(position: [Vector3](https://create.roblox.com/docs/reference/engine/datatypes/Vector3)): bool

Destroys block at position. Returns true if a block was destroyed.

#### getAllBlocks(blockTypes: [ItemType](https://docs.easy.gg/scripting/bedwars-scripting/types/itemtype)\[] | nil): [Block](https://docs.easy.gg/scripting/bedwars-scripting/objects/block)\[]

Returns all blocks in the world. If a set of `blockTypes` is supplied it will only return blocks of that type. <mark style="color:yellow;">**Warning**</mark>: this function is very slow, especially when you do not supply a list of `blockTypes`.

#### getNearbyBlocks(center: [**Vector3**](https://create.roblox.com/docs/reference/engine/datatypes/Vector3), size: [**Vector3**](https://create.roblox.com/docs/reference/engine/datatypes/Vector3)**,** blockTypes: [ItemType](https://docs.easy.gg/scripting/bedwars-scripting/types/itemtype)\[] | nil): [Block](https://docs.easy.gg/scripting/bedwars-scripting/objects/block)\[] | nil

Returns blocks contained in a part centered at the specified `center` with the specified `size`. If a set of `blockTypes` is supplied, it will only return blocks of that type.
