I would like to save all the values in a folder without them directly in the script. So if a new value is added during the game this should also be saved and loaded
my script:
local DSS = game:GetService("DataStoreService")
local datastore = DSS:GetDataStore("GeneralSaveData", "Players")
function generateDataKey(player)
local ret = ("uid_" .. player.userId)
return ret
end
function generateDataTable(player)
local dataTable = {
TestValue = game.Workspace.TestFolder.TestValue.Value
--I thought about doing something like Data = game.Workspace.TestFolder:GetChildren()
}
return dataTable
end
function saveDataForPlayer(player)
local key = generateDataKey(player)
local data = generateDataTable(player)
datastore:SetAsync(key, data)
end
function inputDataToPlayer(player, data)
if data ~= nil then
game.Workspace.TestFolder.TestValue.Value = data.TestValue
end
end
end
function loadDataForPlayer(player)
local key = generateDataKey(player)
local data = datastore:GetAsync(key)
inputDataToPlayer(player, data)
end
game.Players.PlayerAdded:connect(function(player)
loadDataForPlayer(player)
wait ()
while true do
wait (60)
saveDataForPlayer(player)
end
end)
game.Players.PlayerRemoving:connect(saveDataForPlayer)
Is there a way to do this?

1 comment
@Leamir I believe one of the ends (Line 33 or 34) was unnecessary; It gave me a script error when I tried to use this script. Thanks, anyway!