How do I get the Users in DataStore?

I was creating an Admin Panel, and I encountered a problem with datastore.
I wanted to see in a scrolling frame which users have access, so basically I wanted the users to be visible to the Owner, who uses the Admin Panel.

What is my goal?
I want to create an Scrolling Frame within the Frames of people, who are able to use the Admin Panel (So access the datastore and get who is using it)
(See img)

What is the problem?
I created a DataStore where I added into players a Value called “HasAccess”, and if that value is true, it would display the player on the scrolling frame.
I tried getting an ordered/sorted datastore, but seemingly it printed out an empty table.

This is the script:
(In this script I just try to retrieve the whole datastore data when a player joins, if I know this I can get the actual inserting of frames and cloning)

local AccessDataStore = game:GetService("DataStoreService"):GetDataStore("HasAccess")
--Access is a datastore that has ppl with administator

game.Players.PlayerAdded:Connect(function(player)
    
    
local AccessVal = Instance.new("BoolValue")
AccessVal.Name = "HasAccess" 
AccessVal.Parent = player:WaitForChild("AccessFolder") -- Gives BoolValue
    
    
    local Access    
    local S,F = pcall(function()
        Access = AccessDataStore:GetAsync(tostring(player.UserId)) -- Gets player Data
    end)
    local OrderedLayout = game:GetService("DataStoreService"):GetOrderedDataStore("HasAccess"):GetSortedAsync(true,10,0,300):GetCurrentPage()    --why is this table empty?? there is players which use this datastore

    -- Table OrderedLayout  is empty, why?
end)```

Help is appreciated!
1 Like

and

are two completely different data stores. Even though they have the same name, the first one is a normal DataStore, and the second one is an OrderedDataStore. These two datastores don’t sync.

You could try checking all players and if GetAsync says true, add em to the list.

yes, I want all users, not only in server, but generally…

that would be complicated unless you use ordereddatastore and use its listallkeys function.

how can I get all keys from datastore in a table?

This should be helpful.

Hey man, I seemingly cant get it with this ListKeysAsync, im trying to create an Admin Panel but it doesnt print me all Keys, any keys… look

local Options = Instance.new("DataStoreOptions")
Options.AllScopes = true
local AccessDataStore = game:GetService("DataStoreService"):GetDataStore("HasAccess","",Options)

game.Players.PlayerAdded:Connect(function(player)
	
	local AccessVal = Instance.new("BoolValue")
	AccessVal.Name = "HasAccess"
	AccessVal.Parent = player -- We insert boolvalue
	
	local Access	-- Data Value, used later


	local T = AccessDataStore:ListKeysAsync("",10):GetCurrentPage() -- T is {} ??? why, I played the game, shouldn't it be stored?
	for i,v in pairs(T) do
		print("Key: "..v.."Value: "..AccessDataStore:GetAsync(tostring(v.KeyName))) -- nothing
	end
	local S,F = pcall(function()
		Access = AccessDataStore:GetAsync(tostring(player.UserId))
	end)
	print(Access)
	
end)
game.Players.PlayerRemoving:Connect(function(player)
	local Data = nil
	local Access
	local Wasbannedcheck
	local S,F = pcall(function()

		Access = AccessDataStore:SetAsync(player.UserId, player:WaitForChild("HasAccess").Value) -- Set the data
	end)
	if F then
		warn(F)
	end
end)

Check what I replied to @regexman

It works fine for me, i just copyed a script from roblox wiki and it works for me. I have 2 users that played this game and it shows them all. Is this what you have been looking for?

1 Like

I think it might be bc of the parameters you have in the ListKeysAsync, just try this code in the empty script

local DataStore = game:GetService("DataStoreService"):GetDataStore("DataStore-1")

local options = Instance.new("DataStoreOptions")
options.AllScopes = true

wait(5)

local pages = DataStore:ListKeysAsync()

while true do
	local items = pages:GetCurrentPage()
	for _, v in ipairs(items) do
		local value = DataStore:GetAsync(v.KeyName)
		print("User ", v.KeyName, " has this data: ", value)
	end
	if pages.IsFinished then
		break
	end
	pages:AdvanceToNextPageAsync()
end
5 Likes