I’m using a data store, but the code keeps repeating, and I don’t know why, but it overloads DataStoreService. Here’s my code:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local addGui = ReplicatedStorage.FireAddGUI
local DataStoreService = game:GetService("DataStoreService")
local passStore = DataStoreService:GetDataStore("RankStore")
Players.PlayerAdded:Connect(function(plr)
if plr:GetRankInGroup(11635716) >= 254 then
local success, pages = pcall(function()
return passStore:ListKeysAsync()
end)
if success then
local passed = {}
while task.wait(0.1) do
for i, v in pairs(pages:GetCurrentPage()) do
table.insert(passed,v)
print("Player added to passed")
end
if pages.IsFinished == true then
print("Pages finished")
break
end
print("next page")
pages:AdvanceToNextPageAsync()
end
for i, name in pairs(passed) do
local success, result = pcall(function()
return passStore:GetAsync(name.KeyName)
end)
if success then
addGui:FireClient(plr,name.KeyName,result)
print("ui request sent for "..name.KeyName)
end
wait(0.5)
end
end
end
end)
I understand that I have a repeat, but it’s repeating more than it should. I only have two keys, but it infinitely repeats. Why might this be happening? Also, how do I get rid of keys?