So, I've been working on an admin command list recently and I was confused on how to make everyone's data about admins and bans similar to everyone else's data.
I was told to use a Key instead of using a Player's UserId, and I have tried doing this. The one problem is, when you save values to a DataStore with a key, it'll save in 2 columns and 1 row. 1 Column is the Key, and the other is all the data.
I was thinking of saving the data using a string as in
"Player_Id Not_Admin Not_Banned"
or
"Player_Id Admin Not_Banned"
or
"Player_Id Not_Admin Banned"
Just to indicate if they are banned or are admins.
Then it would save as multiple strings, and I could use a for loop.
for _,val in pairs(data) do
if string.match(player.UserId, val) then
print("Existing Data")
else
print("Creating New Data")
end
end
Now, I thought this should work, but it seemed as the game didn't load nor save the data in live servers and studio.
So, now I'm confused on how to fix this.
Here is the full code.
ServerScript in ServerScriptService
local DSS = game:GetService("DataStoreService")
local GDS = DSS:GetDataStore("_admin_bans_")
local Key = "08ufndasyc79cjfomauihcfdn7af3uhgrieavnfiu"
game.Players.PlayerAdded:Connect(function(player)
local dataFolder = Instance.new("Folder")
dataFolder.Name = "DataFolder"
dataFolder.Parent = player
local admin = Instance.new("Folder")
admin.Name = "Admin"
admin.Parent = dataFolder
local banned = Instance.new("Folder")
banned.Name = "Banned"
banned.Parent = dataFolder
local data
local success, err = pcall(function()
data = GDS:GetAsync(Key)
end)
if success then
if type(data) == "table" then
for _,val in pairs(data) do
if string.match(player.UserId, val) then
local args = string.split(val, " ")
if args[2] == "Admin" then
admin.Value = true
elseif args[2] == "Not_Admin" then
admin.Value= false
else
admin.Value = false
end
if args[3] == "Banned" then
banned.Value = true
elseif args [3] == "Not_Banned" then
banned.Value = false
else
banned.Value = false
end
print("Loaded Data")
end
end
end
else
warn("Error Loading Data\n"..err)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local dataFolder = player:WaitForChild("DataFolder")
local admin = dataFolder:WaitForChild("Admin")
local banned = dataFolder:WaitForChild("Banned")
local dataToSave
if admin.Value == true then
if banned.Value == true then
dataToSave = player.UserId.. " Admin Banned"
else
dataToSave = player.UserId.. " Admin Not_Banned"
end
elseif admin.Value == false then
if banned.Value == false then
dataToSave = player.UserId.. " Not_Admin Not_Banned"
else
dataToSave = player.UserId.. " Not_Admin Banned"
end
end
local success, err = pcall(function()
GDS:SetAsync(Key, dataToSave)
end)
if success then
print("Success")
else
warn("Error Saving Data\n"..err)
end
end)
game:BindToClose(function()
for _,player in pairs(game:GetService("Players"):GetPlayers()) do
local dataFolder = player:WaitForChild("DataFolder")
local admin = dataFolder:WaitForChild("Admin")
local banned = dataFolder:WaitForChild("Banned")
local dataToSave
if admin.Value == true then
if banned.Value == true then
dataToSave = player.UserId.. " Admin Banned"
else
dataToSave = player.UserId.. " Admin Not_Banned"
end
elseif admin.Value == false then
if banned.Value == false then
dataToSave = player.UserId.. " Not_Admin Not_Banned"
else
dataToSave = player.UserId.. " Not_Admin Banned"
end
end
local success, err = pcall(function()
GDS:SetAsync(Key, dataToSave)
end)
if success then
print("Success")
else
warn("Error Saving Data\n"..err)
end
end
end)
If you need anymore information I'll be glad to edit this post. Any help is appreciated.

2 comments
Just for clarification, what exactly is the data you are trying to save? Is there two fields, players who are banned and players who have admin priveleges?
Indeed, I was thinking of saving their data using a string formatted with their name and the data thats being saved ^, and using a for loop to match the players name with the strings name