getBucketValue

Retrieves a value stored in a Bucket.

Since the value returned is either a string or null, care should be taken when dealing with numbers and booleans.

Signatures

beacon.getBucketValue(bucketId, key);
beacon.getBucketValue(bucketId, key, playerId);

Parameters

bucketId

The UUID of the bucket to retrieve a value from.

key

They key of the value to fetch.

playerId

Include this parameter to fetch the value for this player. Otherwise fetches the non-player value for the key.

Return Values

Type Notes
String Returns the value, or null if there is no value.

Examples

Fetch the number of kills a player has

const killCount = parseInt(beacon.getBucketValue('d7c0eee0-17bd-495d-88f6-16a815c36587', 'killCount', 'fc4c921c-ba83-4d1b-8470-a08fedf8246f') ?? 0);

Because getBucketValue returns a string, we need to use parseInt to convert the string to a number. If the player has no value yet, the function will return null, so the null-coalescing operator (??) allows falling back to 0 instead.

See Also