Is there a way to get the id of a player (that doesn't need to be on the same server) by the value of the datastore?

I am new in datastore but if there any way to get a player id or the player by the value of the datastore? but it must be noted that there are possibilities that the player is not on the same server or is not online. So basically i want to get a player id by the value of the datastore but the player can be in another server or offline.

so any help?

Thanks for reading.

1 Like

Hello. It is not quite clear what you’re trying to convey by this:

Can you please clarify?

1 Like

This is probably what you want:

1 Like

I think what you’re looking for is Players | Roblox Creator Documentation . Hope it helps!

1 Like

like example if the value is 3 i want to search the players with the value 3

1 Like

no, i want to get a player by the value of the datastore, example i have a save value with a value of 503283203 i want to get the player with the value 503283203

1 Like

Did you at least read the text?

Yes but

I don’t think I’m the one to blame.

Hello. Sorry for the late reply. I was wondering upon your topic and there are two workaround methods of doing this, both of which I’m not too proud of. Anyways, here’s the first one:

You can store all the data in a single datastore entry and call it as required but this method is NOT recommended as it would create pressure on the datastore, thus might slow down saves and loads.

You can, however, use a Master Key Method. You will need to make a master entry to store the list of players whose data is stored, then call upon a loop. Here’s an example:

local ReqVal = 200 -- Make changes here
local dss = game:GetService("DataStoreService")
local myData = dss:GetDataStore("YourDataStoreHere") -- Make changes here

local SavedPlayersTable = {}
local success, masterData = pcall(function() return myData:GetAsync("MasterData") end)
if success then SavedPlayersTable = masterData else warn(masterData) end

script.YourDataLoadingEventHere.Event:Connect(function() -- Make changes here
local eligible = {}
for _,UserId in pairs(SavedPlayerData) do
 local success, PlrData = pcall(function() return myData:GetAsync(UserId) end)

if success then
 if PlrData ~= nil and PlrData == ReqVal then
  table.insert(eligible,UserId)
 end
end
end

print(eligible)
end)

script.YourDataSavingEventHere.Event:Connect(function(Player) -- Make changes here
local Success,Err = pcall(function() 
myData:SetAsync(Player.UserId, script.ExampleValue.Value) -- Make changes here
if success then table.insert(SavedPlayerData,Player.UserId)
else 
warn(Err)
end
end)

game:BindToClose(function()
local Success,Err = pcall(function() myData:SetAsync("MasterData",SavedPlayerData) end)
if Success then print("Success") else warn(Err) end
end)

Sorry for the bad formatting, I’m on phone.

You can’t do that, because datastores are not relational. You would have to iterate, which is not a great idea.

If you wanted to do that, you could use an external database with MySQL, as it’s a relational database.

I believe my Master Key method should work, though I completely agree that it is very inefficient.