I was going through my OrderedDataStores and decided to filter one of them from duplicates.
Basically, the Keys for the stores are meant to be stored like this:
'z'...player.UserId
what I am trying to get rid of are:
's'...player.UserId
't'...player.UserId
-- and other keys.
It basically just converts the string at the front to a new letter and makes sure it isn’t duplicated.
Here is the code:
local OrderedPlayerScore = game.DataStoreService:GetOrderedDataStore("OrderedPlayerLevel")
local Data = OrderedPlayerScore:GetSortedAsync(false,18,1,math.huge)
local CurPage = Data:GetCurrentPage()
for rank, inf in pairs(CurPage) do
if string.sub(inf.key,1,1) then
task.wait()
print(inf.key)
local suc, err = pcall(function()
if OrderedPlayerScore:GetAsync('z'..string.sub(inf.key,2,#inf.key)) and string.sub(inf.key,1,1) ~= 'z' then
OrderedPlayerScore:RemoveAsync(inf.key)
end
if not OrderedPlayerScore:GetAsync(inf.key) then
OrderedPlayerScore:SetAsync("z"..string.sub(inf.key,2,#inf.key),inf.value) print(inf.key)
end
end)
if suc then
OrderedPlayerScore:RemoveAsync(inf.key)
end
end end
But after running it several times, and it seems to have filtered everything without the key 's'
, but the key I need to filter is 'z'
.
Basically:
--Expected result:
z407478547
-- actual result
s407478547