I have a DataStore that saves money and values that represent GUIs being enabled. When I manually changed the Values in ReplicatedStorage (which are then duplicated to a folder in the Client), it saves/loads, but when I don't, it doesn't.
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 local plrDanceFolder = Instance.new('Folder') plrDanceFolder.Name = "danceFolder" plrDanceFolder.Parent = Player for i,v in pairs (game.ReplicatedStorage.danceValues:GetChildren()) do if v:IsA("BoolValue") then v:Clone().Parent = plrDanceFolder end end --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") print(dancesData) for i,v in pairs(dancesData) do local Dance = plrDanceFolder:FindFirstChild(v) if dancesData then Dance.Value = true print("lel") game.ReplicatedStorage:WaitForChild("Remotes").loadAnimEvent:FireClient(Player) end end 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.danceFolder:GetChildren()) do if v:IsA("BoolValue") and v.Value == true 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)
Local Script (RemoteEvent):
local loadAnimEvent = game:GetService("ReplicatedStorage"):WaitForChild("Remotes"):WaitForChild("loadAnimEvent") loadAnimEvent.OnClientEvent:connect(function(plr) print("dances loadin'") local plr = game.Players.LocalPlayer for i,e in pairs (plr.danceFolder:GetChildren()) do if e:IsA("BoolValue") and e.Value == true then print(e) for i,v in pairs (plr.PlayerGui.Dances:GetChildren()) do print("yeet") if v:IsA("TextButton") and v.Name == e.Name then e.Value = true v:Clone().Parent = plr.PlayerGui.dancesGui.dancesFrame.danceFrame.danceScrolling end end end end end)
I feel like the error is possibly coming from the values being replicated from ReplicatedStorage -- I don't think so, though.