Hello!
I’m trying to remove keys of people who’ve joined my game but aren’t friends, however I can’t get it to work for some reason.
Also excuse the horrible variables and not using :GetService, I’m running it in the command line so I don’t need to be fancy or anything. I’m also using DatastoreV2 so that might be contributing to the issue, I really don’t know though.
I was also able to set the data to a blank table, but not actually remove it.
local o = Instance.new('DataStoreOptions')
o:SetExperimentalFeatures({v2 = true})
local ds: DataStore = game.DataStoreService:GetDataStore('PLAYERDATA', nil, o)
local keys = ds:ListKeysAsync(nil, 50)
local f = game.Players:GetFriendsAsync(605492589)
local fs = {}
while true do
for i, v in pairs(f:GetCurrentPage()) do
table.insert(fs, v.Id)
end
if not f.IsFinished then
f:AdvanceToNextPageAsync()
else
break
end
end
print(fs)
while true do
for i, v:DataStoreKey in pairs(keys:GetCurrentPage()) do
if not table.find(fs, tonumber(v.KeyName)) and v.KeyName ~= '605492589' then
print('rm',v.KeyName,ds:RemoveAsync(v.KeyName)) -- no errors
task.wait()
end
end
if not keys.IsFinished then
keys:AdvanceToNextPageAsync()
else
break
end
end
wait(10)
local keys = ds:ListKeysAsync(nil, 50)
while true do
for i, v:DataStoreKey in pairs(keys:GetCurrentPage()) do
print(v.KeyName) -- still prints the keys that should have been removed
end
if not keys.IsFinished then
keys:AdvanceToNextPageAsync()
else
break
end
end