I’m not sure how to title this, but I’m not sure how I should update player data on an interval. I’m trying to avoid the added to queue errors, and this is what I have so far:
local players = game:GetService("Players")
local dataStoreService = game:GetService("DataStoreService")
local bestTimeData = dataStoreService:GetOrderedDataStore("BestTime")
local killsData = dataStoreService:GetOrderedDataStore("Kills")
while true do
for _, player in ipairs(players:GetPlayers()) do
local leaderstats = player.leaderstats
local bestTime = leaderstats["Best Time"].Value
local kills = leaderstats.Kills.Value
pcall(function()
bestTimeData:UpdateAsync(player.UserId, function(oldValue)
if oldValue == bestTime then
return nil
end
return bestTime
end)
killsData:UpdateAsync(player.UserId, function(oldValue)
if oldValue == kills then
return nil
end
return kills
end)
end)
end
wait(20)
end
Is there a better way to do this, or will this even work at all?