Hello! I made a custom tycoon system, however, I’m not sure how to go about saving it.
I tried a solution but it just gave me an error
Error: 104: Cannot store Array in data store. Data stores can only accept valid UTF-8 characters.
I just need a few boolvalues to save when a player leaves and load when a player joins.
Here is the code I use right now (The leaderstats are created after the game starts.)
local data = dss:GetDataStore("example")
function saveprogress(location)
local load = {}
for i,v in pairs(location:GetChildren()) do
table.insert(load,v:Clone())
end
return load;
end
function loadprogress(load,location)
for i,v in pairs(load) do
v.Parent = location
end
end
game.Players.PlayerAdded:Connect(function(p)
local motherfolder = Instance.new("Folder")
motherfolder.Parent = p:WaitForChild("leaderstats")
motherfolder.Name = "Purchased"
for _, v in pairs (workspace.House.Buttons:GetChildren()) do
local value = Instance.new("BoolValue")
value.Parent = motherfolder
value.Name = v.Name
end
local key = "key-"..p.UserId
local save = data:GetAsync(key)
if (save == nil) then
data:SetAsync(key,saveprogress(motherfolder))
else
loadprogress(save,motherfolder)
end
end)
game.Players.PlayerRemoving:Connect(function(p)
local key, motherfolder = "key-".. p.UserId ,p.leaderstats.Purchased
data:SetAsync(key,saveprogress(motherfolder))
end)