I'm trying to create an admin system with ranks etc and I'm having trouble with saving players that I admin along with their ranks. This is my first time using DataStores so please bear with me if I did anything retarded.
I save their admin and their ranks like this:
Module Script
adminModule.Database = DataStoreService:GetDataStore("AdminCommands")
adminModule.AdminList = {28356112} --Preset admin
adminModule.Ranks = {
["28356112"] = {255, 150}, --Preset ranks
["29580606"] = {10} --10 isnt an admin thats why i dont have this userid in AdminList
}
adminModule.Prefix = "?"
local aList
local aRanks
pcall(function()
aList = adminModule.Database:GetAsync("AdminList")
aRanks = adminModule.Database:GetAsync("Ranks")
end)
if not aList then
adminModule.Database:SetAsync("AdminList", adminModule.AdminList)
aList = adminModule.AdminList
end
if not aRanks then
adminModule.Database:SetAsync("Ranks", adminModule.Ranks)
aRanks = adminModule.Ranks
end
--Saving admin
table.insert(aList, userid)
adminModule.Database:SetAsync("AdminList", aList)
--Saving rank
aRanks[tostring(userid)] = {rank} --im using tostring here because i get userid by using game.Players:GetUserIdFromNameAsync and I want to turn userid into the key name
adminModule.Database:SetAsync("Ranks", aRanks)
For some reason, when I use a command that gets all the admins, I sometimes find multiple instances of the same admin who apparently has no rank (if the player has a rank then it would show in the [ ] in front of their name), and apparently has no admin when it clearly shows the player does in the GUI that lists the admins.
https://gyazo.com/65483b40d639d465ee47720b14e1b835
In the GUI I get the admins of the game by using
--Local Script (FireClient from the module)
for i,v in pairs(aList) do
--Text Label creation stuff
for a = 1,#game.Players:GetNameFromUserIdAsync(v) do
--adminName is just a textlabel parented to the UI
adminName.Text = string.sub(game.Players:GetNameFromUserIdAsync(v), 1, a)
wait(0.05)
end

3 comments
Thanks for taking your time to answer my question, but when I joined my game to let the DataStores save my admin, leave, and remove the save function from the PlayerAdded function. It turns out that the admin doesn't save, I don't want to constantly giving people admin each time they join, I want to just admin them once and save their admin.
also what is basekey?
Move the save method wherever you need it. Basekey is the data key, it formats to azarth_useridhere.