PlayerUtil
This module contains utility methods that handle players joining and leaving. As well as utility functions for character access.
Characters Folder
The module works best when a folder named "Characters" exists within workspace. Ideally you create this folder within your project JSON file so that it exists ahead of time.
Functions
getCharactersFolder
This is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts. YieldsReturns the characters folder, creating it if it doesn't exist. This folder is used to store all characters in the game. This folder is created on the server and waited for on the client.
promiseCharacter
PlayerUtil.
promiseCharacter
(
timeOut?:
number?
--
The amount of time to wait before rejecting the promise
) →
Promise
<
Character
>
--
A promise that resolves when the character is retrieved
Returns a promise that resolves with the character of the specified player once their character is within the proper folder.
getPlayerFromCharacterDescendant
Returns the player that owns the specified descendant of a character. Returns nil if the descendant is not a descendant of a character.
getAllLoadedCharacters
PlayerUtil.
getAllLoadedCharacters
(
) →
{
Character
}
--
A table of all the fully loaded characters
forEachCharacter
PlayerUtil.
forEachCharacter
(
func:
(
char:
Character
,
janitor:
Janitor
)
→
(
)
,
--
A passed function to be executed for each character, it is given the character as an argument. Also receives a Janitor object that can be used to clean up any connections made.
) →
Connection
--
A connection that can be Disconnected or Destroyed to stop method's activities.
Takes a function that will be run for every player in the game as well as any future players until the returned connection is disconnected.
forEachPlayer
PlayerUtil.
forEachPlayer
(
) →
Connection
--
A connection that can be Disconnected or Destroyed to stop method's activities.
Takes a function that will be run for every player in the game as well as any future players until the returned connection is disconnected.
onPlayerRemoving
PlayerUtil.
onPlayerRemoving
(
func:
(
)
→
(
)
--
The function to be run when the player disconnects.
) →
Connection
--
A connection that can be Disconnected or Destroyed to stop method's activities.
Takes a function that will be run for a specified player when they leave.