Skip to main content

playersUtil

A simple utility module for working with the Players service.

Functions

playerThumbnailPromise

playersUtil.playerThumbnailPromise(
userIdnumber,
thumbnailTypeEnum.ThumbnailType,
thumbnailSizeEnum.ThumbnailSize
) → Promise<string>

Returns a promise wrapped over Players:GetUserThumbnailAsync.

local PLACE_HOLDER_IMAGE = "rbxassetid://0"

playersUtil.playerThumbnailPromise(userId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420):andThen(function(content)
	print(content)
end):catch(function(errorMessage)
	print(PLACE_HOLDER_IMAGE)
end)

playerFromInstance

playersUtil.playerFromInstance(instanceInstance) → Player?

Returns a player from the given instance, if found. This is an efficient wrapper over Players:GetPlayerFromCharacter as it allows you to get the player object even if the given instance is a deep descendant of some player's character.

laser.Touched:Connect(function(hit)
	local player = playerUtil.playerFromInstance(hit)

	if player ~= nil then
		-- Damage the player
	end
end)

nameFromUserId

playersUtil.nameFromUserId(userIdnumber) → Promise<string>

Returns a promise which is resolved with the user name associated to the user id.

Caching behavior

This method will immediately cache in the name (retrieved from the given user id), so calls for the same user id will return in cached user name immediately.

playersUtil.nameFromUserId(2981707497):andThen(function(username)
	print(username) --> "bubshurb"
end)

userIdFromName

playersUtil.userIdFromName(usernamestring) → Promise<number>

Returns a promise which is resolved with the user id associated to the username.

Caching behavior

This method will immediately cache in the user id (retrieved from the given username), so calls for the same username will return in cached user id immediately.

playersUtil.userIdFromName("bubshurb"):andThen(function(userId)
	print(userId) --> 2981707497
end)

friendsPromise

playersUtil.friendsPromise(useridnumber) → Promise<number>

Returns a promise which is resolved with an array of the player's friend's data.

If the returned promise rejects, it will reject with an empty table (for friends) along with the error message.

playersUtil.friendsPromise(2981707497):andThen(function(friends)
	-- `friends` will be an array of friends pages!

	for _, friendData in friends do
		print(friendData.Username)
		print(friendData.DisplayName)
		print(friendData.Id)
	end
end):catch(function(friends, errorMessage)
	-- `friends` will be an empty array
	print(friends, tostring(errorMessage))
end)

characterAppearanceInfoPromise

playersUtil.characterAppearanceInfoPromise(useridnumber) → Promise<{[string]any}>

Returns a promise which is wrapped around Players:GetCharacterAppearanceInfoAsync.

banHistoryPromise

playersUtil.banHistoryPromise(useridnumber) → Promise<{...}>

Returns a promise which is wrapped around Players:GetBanHistoryAsync.

playersUtil.banHistoryPromise(2981707497):andThen(function(banHistory)
	-- `banHistory` will be an array of ban history pages!

	for _, banData in banHistory do
		print(banData.Ban)
		print(banData.Duration)
		print(banData.StartTime)
		-- and more, etc..
	end
end):catch(function(banHistory, errorMessage)
	-- `banHistory` will be an empty array
	print(banHistory, tostring(errorMessage))
end)

If the returned promise rejects, it will reject with an empty table (for banHistory) along with the error message.

banPromise

playersUtil.banPromise(config{
UserIds{number},
ApplyToUniverseboolean,
Durationnumber,
DisplayReasonstring,
PrivateReasonstring,
ExcludeAltAccountsboolean,
}) → Promise<>

Returns a promise which is wrapped around Players:BanAsync.

unbanPromise

playersUtil.unbanPromise(config{
UserIds{number},
ApplyToUniverseboolean,
}) → Promise<>

Returns a promise which is wrapped around Players:UnbanAsync.

humanoidDescriptionFromOutfitIdPromise

playersUtil.humanoidDescriptionFromOutfitIdPromise(outfitIdnumber) → Promise<>

Returns a promise which is wrapped around Players:GetHumanoidDescriptionFromOutfitId.

humanoidDescriptionFromUserIdPromise

playersUtil.humanoidDescriptionFromUserIdPromise(userIdnumber) → Promise<>

Returns a promise which is wrapped around Players:GetHumanoidDescriptionFromUserId.

createHumanoidModelFromDescriptionPromise

playersUtil.createHumanoidModelFromDescriptionPromise(
descriptionHumanoidDescription,
rigTypeEnum.HumanoidRigType,
assetTypeVerificationEnum.AssetTypeVerification
) → Promise<Model>

Returns a promise which is wrapped around Players:CreateHumanoidModelFromDescription.

createHumanoidModelFromUserIdPromise

playersUtil.createHumanoidModelFromUserIdPromise(userIdnumber) → Promise<Model>

Returns a promise which is wrapped around Players:CreateHumanoidModelFromUserId.

Show raw api
{
    "functions": [
        {
            "name": "playerThumbnailPromise",
            "desc": " \nReturns a [promise](https://eryn.io/roblox-lua-promise/) wrapped over [Players:GetUserThumbnailAsync](https://create.roblox.com/docs/reference/engine/classes/Players#GetUserThumbnailAsync). \n\n```lua\nlocal PLACE_HOLDER_IMAGE = \"rbxassetid://0\"\n\nplayersUtil.playerThumbnailPromise(userId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420):andThen(function(content)\n\tprint(content)\nend):catch(function(errorMessage)\n\tprint(PLACE_HOLDER_IMAGE)\nend)\n```",
            "params": [
                {
                    "name": "userId",
                    "desc": "",
                    "lua_type": "number"
                },
                {
                    "name": "thumbnailType",
                    "desc": "",
                    "lua_type": "Enum.ThumbnailType"
                },
                {
                    "name": "thumbnailSize",
                    "desc": "",
                    "lua_type": "Enum.ThumbnailSize\n"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<string>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 33,
                "path": "src/playersUtil/init.luau"
            }
        },
        {
            "name": "playerFromInstance",
            "desc": " \nReturns a player from the given instance, if found. This is an efficient\nwrapper over [Players:GetPlayerFromCharacter](https://create.roblox.com/docs/reference/engine/classes/Players#GetPlayerFromCharacter) as it allows you\nto get the player object even if the given `instance` is a deep descendant of some player's character.\n \n```lua\nlaser.Touched:Connect(function(hit)\n\tlocal player = playerUtil.playerFromInstance(hit)\n\n\tif player ~= nil then\n\t\t-- Damage the player\n\tend\nend)\n```",
            "params": [
                {
                    "name": "instance",
                    "desc": "",
                    "lua_type": "Instance"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Player?\n"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 59,
                "path": "src/playersUtil/init.luau"
            }
        },
        {
            "name": "nameFromUserId",
            "desc": "Returns a [promise](https://eryn.io/roblox-lua-promise/) which is resolved with the user name\nassociated to the user id. \n\n:::tip Caching behavior\nThis method will immediately cache in the name (retrieved from the given user id), so calls\nfor the same user id will return in cached user name immediately.\n:::\n\n```lua\nplayersUtil.nameFromUserId(2981707497):andThen(function(username)\n\tprint(username) --> \"bubshurb\"\nend)\n```",
            "params": [
                {
                    "name": "userId",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<string>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 90,
                "path": "src/playersUtil/init.luau"
            }
        },
        {
            "name": "userIdFromName",
            "desc": "Returns a [promise](https://eryn.io/roblox-lua-promise/) which is resolved with the user id \nassociated to the username.\n\n:::tip Caching behavior\nThis method will immediately cache in the user id (retrieved from the given username), so calls\nfor the same username will return in cached user id immediately.\n:::\n\n```lua\nplayersUtil.userIdFromName(\"bubshurb\"):andThen(function(userId)\n\tprint(userId) --> 2981707497\nend)\n```",
            "params": [
                {
                    "name": "username",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<number>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 132,
                "path": "src/playersUtil/init.luau"
            }
        },
        {
            "name": "friendsPromise",
            "desc": "Returns a [promise](https://eryn.io/roblox-lua-promise/) which is resolved with an array of the player's\nfriend's data.\n\nIf the returned promise rejects, it will reject with an empty table (for `friends`) along with the\nerror message.\n\n```lua\nplayersUtil.friendsPromise(2981707497):andThen(function(friends)\n\t-- `friends` will be an array of friends pages!\n\n\tfor _, friendData in friends do\n\t\tprint(friendData.Username)\n\t\tprint(friendData.DisplayName)\n\t\tprint(friendData.Id)\n\tend\nend):catch(function(friends, errorMessage)\n\t-- `friends` will be an empty array\n\tprint(friends, tostring(errorMessage))\nend)\n```",
            "params": [
                {
                    "name": "userid",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<number>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 181,
                "path": "src/playersUtil/init.luau"
            }
        },
        {
            "name": "characterAppearanceInfoPromise",
            "desc": "Returns a [promise](https://eryn.io/roblox-lua-promise/) which is wrapped around\n[Players:GetCharacterAppearanceInfoAsync](https://create.roblox.com/docs/reference/engine/classes/Players#GetCharacterAppearanceInfoAsync).",
            "params": [
                {
                    "name": "userid",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<{[string]: any}>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 218,
                "path": "src/playersUtil/init.luau"
            }
        },
        {
            "name": "banHistoryPromise",
            "desc": "Returns a [promise](https://eryn.io/roblox-lua-promise/) which is wrapped around\n[Players:GetBanHistoryAsync](https://create.roblox.com/docs/reference/engine/classes/Players#GetBanHistoryAsync).\n\n```lua\nplayersUtil.banHistoryPromise(2981707497):andThen(function(banHistory)\n\t-- `banHistory` will be an array of ban history pages!\n\n\tfor _, banData in banHistory do\n\t\tprint(banData.Ban)\n\t\tprint(banData.Duration)\n\t\tprint(banData.StartTime)\n\t\t-- and more, etc..\n\tend\nend):catch(function(banHistory, errorMessage)\n\t-- `banHistory` will be an empty array\n\tprint(banHistory, tostring(errorMessage))\nend)\n```\n\nIf the returned promise rejects, it will reject with an empty table (for `banHistory`) along with the\nerror message.",
            "params": [
                {
                    "name": "userid",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<{...}>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 250,
                "path": "src/playersUtil/init.luau"
            }
        },
        {
            "name": "banPromise",
            "desc": "Returns a [promise](https://eryn.io/roblox-lua-promise/) which is wrapped around\n[Players:BanAsync](https://create.roblox.com/docs/reference/engine/classes/Players#BanAsync).",
            "params": [
                {
                    "name": "config",
                    "desc": "",
                    "lua_type": "{\n\tUserIds: { number },\n\tApplyToUniverse: boolean,\n\tDuration: number,\n\tDisplayReason: string,\n\tPrivateReason: string,\n\tExcludeAltAccounts: boolean,\n}"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 287,
                "path": "src/playersUtil/init.luau"
            }
        },
        {
            "name": "unbanPromise",
            "desc": "Returns a [promise](https://eryn.io/roblox-lua-promise/) which is wrapped around\n[Players:UnbanAsync](https://create.roblox.com/docs/reference/engine/classes/Players#UnbanAsync).",
            "params": [
                {
                    "name": "config",
                    "desc": "",
                    "lua_type": "{\n\tUserIds: { number },\n\tApplyToUniverse: boolean,\n}"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 307,
                "path": "src/playersUtil/init.luau"
            }
        },
        {
            "name": "humanoidDescriptionFromOutfitIdPromise",
            "desc": "Returns a [promise](https://eryn.io/roblox-lua-promise/) which is wrapped around\n[Players:GetHumanoidDescriptionFromOutfitId](https://create.roblox.com/docs/reference/engine/classes/Players#GetHumanoidDescriptionFromOutfitId).",
            "params": [
                {
                    "name": "outfitId",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 323,
                "path": "src/playersUtil/init.luau"
            }
        },
        {
            "name": "humanoidDescriptionFromUserIdPromise",
            "desc": "Returns a [promise](https://eryn.io/roblox-lua-promise/) which is wrapped around\n[Players:GetHumanoidDescriptionFromUserId](https://create.roblox.com/docs/reference/engine/classes/Players#GetHumanoidDescriptionFromUserId).",
            "params": [
                {
                    "name": "userId",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 336,
                "path": "src/playersUtil/init.luau"
            }
        },
        {
            "name": "createHumanoidModelFromDescriptionPromise",
            "desc": "Returns a [promise](https://eryn.io/roblox-lua-promise/) which is wrapped around\n[Players:CreateHumanoidModelFromDescription](https://create.roblox.com/docs/reference/engine/classes/Players#CreateHumanoidModelFromDescription).",
            "params": [
                {
                    "name": "description",
                    "desc": "",
                    "lua_type": "HumanoidDescription"
                },
                {
                    "name": "rigType",
                    "desc": "",
                    "lua_type": "Enum.HumanoidRigType"
                },
                {
                    "name": "assetTypeVerification",
                    "desc": "",
                    "lua_type": "Enum.AssetTypeVerification\n"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<Model>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 349,
                "path": "src/playersUtil/init.luau"
            }
        },
        {
            "name": "createHumanoidModelFromUserIdPromise",
            "desc": "Returns a [promise](https://eryn.io/roblox-lua-promise/) which is wrapped around\n[Players:CreateHumanoidModelFromUserId](https://create.roblox.com/docs/reference/engine/classes/Players#CreateHumanoidModelFromUserId).",
            "params": [
                {
                    "name": "userId",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<Model>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 368,
                "path": "src/playersUtil/init.luau"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "playersUtil",
    "desc": " \n\nA simple utility module for working with the [Players](https://create.roblox.com/docs/reference/engine/classes/Players) service.",
    "source": {
        "line": 8,
        "path": "src/playersUtil/init.luau"
    }
}