this is for a save queue. when the value changes the player is supposed to get added to a table in which the players in the table will get saved
-- add to save queue if changed
for i, v in ipairs(player.Settings:GetDescendants()) do
v.Changed:Connect(function()
table.insert(players_to_save,player) -- line 63, as mentioned in da output
print(player.DisplayName.." settings have changed and are now in the save queue")
end)
end
local dss = game:GetService("DataStoreService")
local ds = dss:GetDataStore("SettingsDataStore")
local players = game:GetService("Players")
local players_to_save = {} -- table
local auto_save_interval = 120 -- every 120 seconds
local error = game.ReplicatedStorage.Extras.Message
im not sure what you mean, here’s the whole script:
local dss = game:GetService("DataStoreService")
local ds = dss:GetDataStore("SettingsDataStore")
local players = game:GetService("Players")
local players_to_save = {}
local auto_save_interval = 120 -- every 120 seconds
local error = game.ReplicatedStorage.Extras.Message
local function save(player)
-- if loaded correctly
if player.LoadedCorrectly[script.Name].Value == true then
local settings = player:WaitForChild("Settings")
local key = "Settings_"..player.UserId
local table = {}
for i,setting in ipairs(settings:GetChildren()) do
table[setting.Name] = setting.Value
end
local success, errormessage = pcall(function()
ds:SetAsync(key, table)
end)
if success then
-- yay :]
else
print(script.Name.." save failed")
warn(errormessage)
local error = error:Clone()
error.Parent = player.PlayerGui.PopUps
error.Message.Text = ("Your "..script.Name.." failed to save")
end
end
end
players.PlayerAdded:Connect(function(player)
local key = "Settings_"..player.UserId
local table = {}
local success, errormessage = pcall(function()
table = ds:GetAsync(key) or {}
end)
-- if success, set loaded correctly value to true
if success then
player:WaitForChild("LoadedCorrectly"):WaitForChild(script.Name).Value = true
else
print(script.Name.." failed to load")
warn(errormessage)
local error = error:Clone()
error.Parent = player.PlayerGui.PopUps
error.Message.Text = ("Your "..script.Name.." failed to load")
end
-- make values in folder
for field, value in pairs(table) do
local setting_value = player:WaitForChild("Settings"):WaitForChild(field)
setting_value.Value = value
end
-- add to save queue if changed
for i, v in ipairs(player.Settings:GetDescendants()) do
v.Changed:Connect(function()
table.insert(players_to_save,player)
print(player.DisplayName.." settings have changed and are now in the save queue")
end)
end
end)
-- when leaving, if needed
players.PlayerRemoving:Connect(function(player)
if table.find(players_to_save,player) then
save(player)
table.remove(players_to_save,table.find(players_to_save,player))
end
end)
-- autosave, if needed
while task.wait(auto_save_interval) do
for i, player in ipairs(players_to_save) do
save(player)
table.remove(players_to_save,table.find(players_to_save,player))
end
end
game:BindToClose(function()
if not game:GetService("RunService"):IsStudio() and #players:GetPlayers() > 1 then
for i, player in ipairs(players:GetPlayers()) do
save(player)
end
end
end)