> 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/teamservice.md).

# TeamService

Example usage:

```lua
-- Gamemode: Tag
-- Hitting players makes them join your team.
-- Once everyone is on the same team the game ends.
Events.EntityDamage(function(event)
    -- Can only tag players
    if not event.entity:getPlayer() then
        return
    end
    -- Make sure the tagger is a player
    if (not event.fromEntity or not event.fromEntity:getPlayer()) then
        return
    end
    
    local attackerTeam = TeamService.getTeam(event.fromEntity:getPlayer())
    TeamService.setTeam(event.entity:getPlayer(), attackerTeam)
    
    -- Check that all teams besides the attackerTeam are empty
    -- If so give win to attacker team
    local gameOver = true
    for i, team in ipairs(TeamService.getAllTeams()) do
        if (team == attackerTeam) then
            continue
        end
        
        -- If another team has players the game is not over
        if #team:getInGamePlayers() > 0 then
            gameOver = false
            break
        end
    end
    
    -- Give out win
    if gameOver then
        MatchService.endMatch(attackerTeam)
    end
end)
```

### Functions

#### getTeam(player: [Player](broken://pages/fOfVQF5nlALekCoylPz2)): [Team](/scripting/bedwars-scripting/objects/team.md) | nil

Returns player's team. If player is not on a team this will return nil.

#### setTeam(player: [Player](/scripting/bedwars-scripting/objects/player.md), team: [Team](/scripting/bedwars-scripting/objects/team.md))

Change the team of a player.

#### getAllTeams(): [Team](/scripting/bedwars-scripting/objects/team.md)\[]

Returns table of all teams.

#### getTeamBed(team: [Team](/scripting/bedwars-scripting/objects/team.md)): [Block](/scripting/bedwars-scripting/objects/block.md)

Returns the block instance of the given team's bed.


---

# 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/teamservice.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.
