> ## Documentation Index
> Fetch the complete documentation index at: https://ugcore.urging.ch/llms.txt
> Use this file to discover all available pages before exploring further.

# Permissions: groups

> Staff groups with weights, inheritance and targeting.

<Badge color="blue">Server</Badge> Part of [Permissions](/api/permissions).

## Groups

Groups come from `config/permissions.lua`. Read them with `GetGroupDefinition`.

### AddGroup

```lua theme={"dark"}
UgCore.Permissions.AddGroup(target, group, by?) -> ok, errorCode
```

**MUST run in a thread.** Adds the target to the group and applies it right away. Adding a member again does nothing and returns `true`.

<ResponseField name="group" type="string" required>A group from `config/permissions.lua`.</ResponseField>
<ResponseField name="by" type="string">Who added it. Up to 64 characters.</ResponseField>

### RemoveGroup

```lua theme={"dark"}
UgCore.Permissions.RemoveGroup(target, group) -> ok, removed, errorCode
```

**MUST run in a thread.** `removed` is `false` when the target was not a member. Also deletes stored memberships of groups no longer in the config.

### GetGroups

```lua theme={"dark"}
UgCore.Permissions.GetGroups(target) -> string[]
```

The target's groups, highest weight first. Inherited groups are not listed.

### IsInGroup

```lua theme={"dark"}
UgCore.Permissions.IsInGroup(target, group) -> boolean
```

True for direct members and through inheritance: a `founder` that inherits `admin` is also in `admin`.

### GetWeight

```lua theme={"dark"}
UgCore.Permissions.GetWeight(target) -> integer
```

The highest weight of the target's groups. `0` without groups.

### CanTarget

```lua theme={"dark"}
UgCore.Permissions.CanTarget(actor, target) -> boolean
```

True when `actor` has a strictly higher weight than `target`. Source `0`, the server console, outranks everyone and is outranked by no one.

```lua theme={"dark"}
UgCore.Commands.Register('kick', {
    permission = 'my-admin.kick',
    args = { { name = 'target', type = 'player' } },
}, function(source, args)
    if not UgCore.Permissions.CanTarget(source, args.target) then
        return
    end

    UgCore.Players.Kick(args.target)
end)
```

### GetGroupDefinition

```lua theme={"dark"}
UgCore.Permissions.GetGroupDefinition(group) -> { label, weight, inherits?, permissions }?
```

A copy of the group from the config. `nil` for unknown groups.

<Warning>`IsInGroup`, `GetGroups`, `GetWeight` and `CanTarget` only know memberships managed by UgCore, not `add_principal` lines in `server.cfg`.</Warning>


## Related topics

- [UgCore.Commands](/api/commands.md)
- [Inventory: containers](/api/inventory-containers.md)
- [Using modules](/developers/modules.md)
- [Permissions and groups](/owners/permissions.md)
- [UgCore.Permissions](/api/permissions.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.