ðŸ§ąBlockService

Service for placement and removal of blocks.

Example usage:

-- 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, position: Vector3): bool

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

getBlockAt(position: Vector3): Block | nil

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

getAboveRandomBlock(aboveBlockTypes: ItemType[] | nil): 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): bool

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

getAllBlocks(blockTypes: ItemType[] | nil): Block[]

Returns all blocks in the world. If a set of blockTypes is supplied it will only return blocks of that type. Warning: this function is very slow, especially when you do not supply a list of blockTypes.

getNearbyBlocks(center: Vector3, size: Vector3, blockTypes: ItemType[] | nil): 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.

Last updated