Player Service
Version: public v1
This module is new and might recieve updates in future. If you have any feature suggestions or bug reports, comment on this post.
Features
- Camel case variable names (
name
,displayName
) - Extra functions (
player:ban(<reason>)
,player:unban()
) - More information (
registerDate
) - Ability to interact with offline players
Getting started
To get a player object, simply run playerService.get(<UserId> | <Player>)
local playerService = require(<Path to module>)
local player = playerService.get(3523014477)
Now, lets interact with it:
print(player.name .. "'s account is " .. player.accountAge .. " days old.")
Well, that would be easier to do with regular player instance, let’s do something more interesting:
print(player.name .. "'s account is " .. player.accountAge .. " days old.\n"
.."Is he banned? " .. tostring(player.banned) .. " Is he ingame? " .. tostring(player.ingame))
ingame
property is there for a reason, this module works even if the person is offline! You can interact with players that’s not even ingame, just make sure you remove player object from your scripts to prevent memory leaks.
Now lets try saving & loading user’s data:
if not player.datastore:get('JoinedWhen') then
player.datastore:set('JoinedWhen', player.accountAge)
end
print(player.name .. ' joined when his account was ' .. player.datastore:get('JoinedWhen') .. ' days old!')
Yeah, its simple as that, you don’t have to pcall or check for errors, this module does that for you automatically, player doesn’t even have to be ingame!
Player online properties:
Player offline properties:
API Reference
Properties:
name <string>
displayName <string>
id <number>
accountAge <number>
registerDate <number>
banned <boolean>
banReason <any>
ingame <bool>
instance <Player>
character <Model>
CharacterAdded <Signal>
Methods:
player:kick(reason)
player:ban(reason)
player:unban()
player.datastore:get(key)
player.datastore:set(key, value
player:getInfo()
player:getInfo()
Returns:
{
Devices = {
['KeyboardEnabled'] = true,
['GyroscopeEnabled'] = false,
...
},
Focused = true,
Tick = tick() --user's tick
}
If timed out, kicks
Configurables
Access by module.config
config.DATASTORE_RETRIES - 5
config.DATASTORE_RETRY_COOLDOWN - 1 // Seconds
config.DATASTORE_PREFIX - "PS-"
CLIENT_CALL_TIMEOUT - 5 // Seconds
Roblox Marketplace
File.rbxm (5.5 KB)