> For the complete documentation index, see [llms.txt](https://docs.easy.gg/scripting/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.easy.gg/scripting/bedwars-scripting/services/blockservice.md).

# 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](broken://pages/FvdgRy7Bq206vdjUGPn7), 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](/scripting/bedwars-scripting/objects/block.md) | nil

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

#### getAboveRandomBlock(aboveBlockTypes: [ItemType](broken://pages/FvdgRy7Bq206vdjUGPn7)\[] | 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](/scripting/bedwars-scripting/types/itemtype.md)\[] | nil): [Block](/scripting/bedwars-scripting/objects/block.md)\[]

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](/scripting/bedwars-scripting/types/itemtype.md)\[] | nil): [Block](/scripting/bedwars-scripting/objects/block.md)\[] | 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.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
