Hi! I’m trying to store “roles” inside of Roblox, like Discord. Roles will be given in-game, created in-game, and edited in-game. I need to be able to:
- see all the roles a player has,
- the info of a role (name, description, etc),
- see every single role.
i’ve looked into :ListKeysAsync(), but theres no way to get the value inside that key without sending an extra get request. i’ve looked into “chunks”, but it doesn’t feel like a very scalable solution with how my datastore is set up right now.
how my datastore is set up right now:
local PlayerDataStore = {
[98432423] = { -- A UserId
Roles = {123} -- A bunch of role Ids
}
}
local SystemDataStore = {
Roles = {
[123] = { -- The role ID
Name = "Name",
Description = "Description",
-- Some other useful data...
Players = {
948294832,
943254354363,
432849032432432, -- UserIds
}
}
-- A bunch of other roles
}
}
-- Heres the problem
local function makeChanges(roleId, newRoleInfo)
local data = SystemDataStore.Roles -- Get every roles data using a :GetAsync() request...
data[roleId] = newRoleInfo
-- Do some checks so were only updating the players that had their roles changed...
for index, userId in newRoleInfo.Players do
local playerData = PlayerDataStore[userId] -- run a :UpdateAsync() call and give/remove the role from their "Roles" list
end
end
This works great, but it reaches datastore limits very quickly. especially if a lot of players were given/revoked a role.
Limitations
- Must be able to fetch ALL roles, and some “basic” data a long with every role (name & description).
- Should be able to see every player that has that role.
- Should be able to see every role a player has.
- Should be able to take away or remove a group of players role.
- Should be fairly scalable
- Should not spam :GetAsync(), :SetAsync(), etc…
Is this only possible with external datastores at the moment?