Skip to main content

Badge

Badge management class for awarding badges to players.

Use the Badge.add method to add badges to the cache.

Example:

-- Setup
local Badge = require(game.ReplicatedStorage.Packages.Badge)

Badge.add("BadgeName", 999999999)

-- Server
local hasBadge = Badge.has(player, "BadgeName")

print(`Player has badge: {hasBadge}!`)

if not hasBadge then
	Badge.award(player, "BadgeName")
end

Install with wally by adding the following to your wally.toml:

Badge = "dig1t/badge@1.0.5"

Functions

add

Badge.add(
namestring,--

The name of the badge.

badgeIdnumber--

The id of the badge.

) → ()

Adds a badge to the cache.

Badge.add("BadgeName", 999999999)

has

Badge.has(
playerPlayer | number,--

The player or userId to check.

badgeNamestring--

The name of the badge.

) → boolean--

Whether the player has the badge or not.

Checks if a player has a badge.

local hasBadge = Badge.has(player, "BadgeName")

award

Badge.award(
playerPlayer | number,--

The player or userId to award the badge to.

badgeNamestring--

The name of the badge.

) → boolean--

Whether the badge was awarded or not. If the badge was already awarded, this will return true.

Awards a badge to a player.

local awarded: boolean = Badge.award(player, "BadgeName")

if not awarded then
	print("Failed to award badge!")
end

print("Badge awarded!")
Show raw api
{
    "functions": [
        {
            "name": "add",
            "desc": "Adds a badge to the cache.\n\n```lua\nBadge.add(\"BadgeName\", 999999999)\n```",
            "params": [
                {
                    "name": "name",
                    "desc": "The name of the badge.",
                    "lua_type": "string"
                },
                {
                    "name": "badgeId",
                    "desc": "The id of the badge.",
                    "lua_type": "number"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 50,
                "path": "src/Badge/init.luau"
            }
        },
        {
            "name": "has",
            "desc": "Checks if a player has a badge.\n\n```lua\nlocal hasBadge = Badge.has(player, \"BadgeName\")\n```",
            "params": [
                {
                    "name": "player",
                    "desc": "The player or userId to check.",
                    "lua_type": "Player | number"
                },
                {
                    "name": "badgeName",
                    "desc": "The name of the badge.",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "Whether the player has the badge or not.",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 68,
                "path": "src/Badge/init.luau"
            }
        },
        {
            "name": "award",
            "desc": "Awards a badge to a player.\n\n```lua\nlocal awarded: boolean = Badge.award(player, \"BadgeName\")\n\nif not awarded then\n\tprint(\"Failed to award badge!\")\nend\n\nprint(\"Badge awarded!\")\n```",
            "params": [
                {
                    "name": "player",
                    "desc": "The player or userId to award the badge to.",
                    "lua_type": "Player | number"
                },
                {
                    "name": "badgeName",
                    "desc": "The name of the badge.",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "Whether the badge was awarded or not. If the badge was already awarded, this will return true.",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 109,
                "path": "src/Badge/init.luau"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "Badge",
    "desc": "Badge management class for awarding badges to players.\n\nUse the `Badge.add` method to add badges to the cache.\n\nExample:\n```lua\n-- Setup\nlocal Badge = require(game.ReplicatedStorage.Packages.Badge)\n\nBadge.add(\"BadgeName\", 999999999)\n\n-- Server\nlocal hasBadge = Badge.has(player, \"BadgeName\")\n\nprint(`Player has badge: {hasBadge}!`)\n\nif not hasBadge then\n\tBadge.award(player, \"BadgeName\")\nend\n```\n\nInstall with wally by adding the following to your `wally.toml`:\n```toml\nBadge = \"dig1t/badge@1.0.5\"\n```",
    "source": {
        "line": 37,
        "path": "src/Badge/init.luau"
    }
}