i know that i can’t accually save instances but im trying to save the properties of a gui and the gui’s descendants’ properties as well.
but im not sure how to do it
this is in a serverscript
local player = players.LocalPlayer
local playerui = player.PlayerGui
local GUI = playerui:WaitForChild("ScreenGui")
local dataStoreService = game:GetService("DataStoreService")
local dataStore = dataStoreService:GetDataStore("Song1")
local tries = 3
local dataloaded = false
local function set(plr)
if dataloaded then
local key = plr.UserId
local count = 0
local data = {}
for i, Ui in ipairs(GUI:GetDescendants()) do
table.insert(data,{
["Parent"] = Ui.Parent;
["name"] = Ui.Name;
["Color"] = Ui.BackgroundColor3;
["Value"] = Ui.Value;
["transparancy"] = Ui.BackgroundTransparancy;
["SoundId"] = Ui:FindFirstChildWhichIsA("Sound").SoundId;
})
end
local success, err
repeat
success, err = pcall(function()
dataStore:SetAsync(key, data)
end)
count = count + 1
until count >= tries or success
if not success then
warn("Data could not be set." .. tostring(err))
return
end
else
warn("Data has not been loaded. Do not attempt to set data when it has not been loaded.")
return
end
end
local function get(plr)
local key = plr.UserId
local count = 0
local data
local success, err
repeat
success, err = pcall(function()
data = dataStore:GetAsync(key)
end)
count = count + 1
until count >= tries or success
if not success then
warn("Failed to read data." .. tostring(err))
plr:Kick("Failed to read data. Please rejoin the game.")
return
end
if data then
for i, saved in ipairs(data) do
local loadedModel = game.ReplicatedStorage:FindFirstChild(saved.name):Clone()
if loadedModel then
loadedModel.BackgroundColor3 = (saved.Color)
loadedModel.BackgroundTransparency = (saved.transparancy)
loadedModel.Value = (saved.Value)
loadedModel.SoundId = (saved.SoundId)
loadedModel.Parent = (saved.Parent)
else
return
end
end
dataloaded = true
return data
else
dataloaded = true
return {}
end
end
players.PlayerAdded:Connect(get)
players.PlayerRemoving:Connect(set)
game:BindToClose(function()
for i, plr in ipairs(players:GetPlayers()) do
set(plr)
end
end)
there are more than just values. when the resourced gets cloned from replicated storage, i need it and its descendants to load the saved data…
is there somthing i did wrong? thanks for the help