I am just learning how to use Ordered Datastores so I don't know too much about them yet. I looked on the wiki and came up with this small script for testing. I would like to know how I pull out specific values from within the Datastore. I save all of my values under the same datastore, PointStore, so I am just wondering how I could pull out and order just the Points value from each player. As of right now it doesn't seem to be doing anything but printing out general values that are set within the script. I just would like to know how I print out just their points and not just this random number.
local ds = game:GetService("DataStoreService"):GetOrderedDataStore("PointStore") ds:SetAsync("Telamon", 10) ds:SetAsync("Tone", 12) ds:SetAsync("Sorcus", 8) ds:SetAsync("Merely", 9) ds:SetAsync("StickMasterLuke", 10) local pages = ds:GetSortedAsync(false, 50) data = pages:GetCurrentPage() while wait(5) do for i, v in pairs(data) do print(i.." "..v.key..": "..v.value.." points") end end
This is my datastore script:
local ds = game:GetService("DataStoreService"):GetDataStore("PointStore") function SavePlayer(OldPlayer) local pts = OldPlayer:FindFirstChild("Points").Value local kills = OldPlayer:FindFirstChild("Kills").Value local tbl = { [1] = { ['pts'] = pts, ['kills'] = kills } } ds:SetAsync("UserData_" .. OverAllAsyncCode, tbl) end game.OnClose = function() SaveState() end game.Players.PlayerAdded:connect(function(NewPlayer) local pts = Instance.new("IntValue", NewPlayer) pts.Name = "Points" local kills = Instance.new("IntValue", NewPlayer) kills.Name = "Kills" if (ds:GetAsync("UserData_" .. NewPlayer.userId)) then for _, v in pairs(ds:GetAsync("UserData_" .. NewPlayer.userId)) do pts.Value = v['pts'] kills.Value = v['kills'] end else pts.Value = 0 kills.Value = 0 end end) game.Players.ChildRemoved:connect(SavePlayer) game.Players.PlayerRemoving:connect(function(plr) SavePlayer(plr) end) while wait(60) do SaveState() end