I'm trying to make a DataStore script that saves and loads GUI buttons and money; it saves/loads money just fine, but it doesn't save/load the GUI buttons; I think there's a problem with the loading.
SCRIPT:
local DataStoreService = game:GetService("DataStoreService") local ds = DataStoreService:GetDataStore("danceSave") local ds2 = DataStoreService:GetDataStore("MoneySave") game:GetService("Players").PlayerAdded:Connect(function(Player) --When the player joins the game, load value. local Stats = Instance.new('Folder') Stats.Name = "leaderstats" local Money = Instance.new('NumberValue', Stats) Money.Name = "Money" Stats.Parent = Player --load data local moneyData; local dancesData; local CanSave = Instance.new('BoolValue', Player) CanSave.Name = "CanSaveData" CanSave.Value = true local DataFetchSuccess, ErrorMessage = pcall(function() moneyData = ds2:GetAsync(tostring(Player.UserId)) dancesData = ds:GetAsync(tostring(Player.UserId)) end) if DataFetchSuccess then if moneyData ~= nil then --This could be where the problem is print("Money save found") Money.Value = moneyData else print("No money save found.") Money.Value = 0 -- Where money value is changed to 0 end --print(Money.Value) print("k") if dancesData ~= nil then print("k") for i,v in pairs(dancesData) do print(v) local Dance = Player.PlayerGui.Dances:FindFirstChild(v) if dancesData then Dance:Clone().Parent = Player.PlayerGui.dancesGui.dancesFrame.danceFrame.danceScrolling end end print("k") end else Player.CanSaveData.Value = false Player:Kick("Your data failed to load! Please rejoin.") end end) game:GetService("Players").PlayerRemoving:Connect(function(Player) -- When the player leaves the game, data must save. if Player.CanSaveData.Value == false then return end --There could also be a problem with saving the money local moneyData = Player.leaderstats.Money.Value local dancesToSave = {} print(moneyData) print(dancesToSave) for i,v in pairs (Player.PlayerGui.dancesGui.dancesFrame.danceFrame.danceScrolling:GetChildren()) do print("loop de loop") if v:IsA("TextButton") then table.insert(dancesToSave, v.Name) print(v.Name) end end local DataWriteSuccess, ErrorMessage = pcall(function() print("Saving "..Player.Name.."s stats") ds:SetAsync(tostring(Player.UserId), dancesToSave) print("ok0") ds2:SetAsync(tostring(Player.UserId), moneyData) print("ok") end) if not DataWriteSuccess then local Retry_Count = 0 while Retry_Count < 6 do wait(60) local Succeed, Error = pcall(function() print("Attempting to save "..Player.Name.."'s stats.") ds:SetAsync(tostring(Player.UserId), dancesToSave) ds2:SetAsync(tostring(Player.UserId), moneyData) end) if Succeed then print("Saved "..Player.Name.."'s stats") break end Retry_Count = Retry_Count + 1 end end end)
There are no errors.
It doesn't save objects. Just save the amount of points that each player has, and then have the GUI display that from the localscript; don't store and clone the objects themselves.