playersUtil
A simple utility module for working with the Players service.
Functions
playerThumbnailPromise
playersUtil.
playerThumbnailPromise
(
userId:
number
,
thumbnailType:
Enum.ThumbnailType
,
thumbnailSize:
Enum.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
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
(
userId:
number
) →
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
(
username:
string
) →
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
(
userid:
number
) →
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
(
userid:
number
) →
Promise
<
{
[
string
]
:
any
}
>
Returns a promise which is wrapped around Players:GetCharacterAppearanceInfoAsync.
banHistoryPromise
playersUtil.
banHistoryPromise
(
userid:
number
) →
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
}
,
ApplyToUniverse:
boolean
,
Duration:
number
,
DisplayReason:
string
,
PrivateReason:
string
,
ExcludeAltAccounts:
boolean
,
}
) →
Promise
<
>
Returns a promise which is wrapped around Players:BanAsync.
unbanPromise
playersUtil.
unbanPromise
(
config:
{
UserIds:
{
number
}
,
ApplyToUniverse:
boolean
,
}
) →
Promise
<
>
Returns a promise which is wrapped around Players:UnbanAsync.
humanoidDescriptionFromOutfitIdPromise
playersUtil.
humanoidDescriptionFromOutfitIdPromise
(
outfitId:
number
) →
Promise
<
>
Returns a promise which is wrapped around Players:GetHumanoidDescriptionFromOutfitId.
humanoidDescriptionFromUserIdPromise
playersUtil.
humanoidDescriptionFromUserIdPromise
(
userId:
number
) →
Promise
<
>
Returns a promise which is wrapped around Players:GetHumanoidDescriptionFromUserId.
createHumanoidModelFromDescriptionPromise
playersUtil.
createHumanoidModelFromDescriptionPromise
(
rigType:
Enum.HumanoidRigType
,
assetTypeVerification:
Enum.AssetTypeVerification
) →
Promise
<
Model
>
Returns a promise which is wrapped around Players:CreateHumanoidModelFromDescription.
createHumanoidModelFromUserIdPromise
Returns a promise which is wrapped around Players:CreateHumanoidModelFromUserId.