Hi guys, I am trying to use DataStores in my new game but when I go to test them, the values don't load and I'm not sure why they aren't loading. I did have an error before I made a tiny amendment to the script, it said:
EDIT: I now keep getting this error. It occurs on the lines where the asynchronous methods of the data store are used (Line 16 and line 89 is where I started getting these errors, it alternates between the two randomly.)
HTTP 403 (HTTP/1.1 403 XSRF Token Validation Failed)
Now it does not show anything in the output and I'm not sure how to fix the script. Any help is appreciated, thanks!
Script (EDITED, found out why it wasn't functioning at all but now it won't progress through the clearAllValues function as it throws the token validation error above after the "if ds ~= nil then" line):
math.randomseed(tick()) rs = game:GetService("ReplicatedStorage") function clearAllValues(item,ds,plr) for i,v in pairs(item:GetChildren()) do if not v:IsA("Folder") then v:Destroy() end clearAllValues(v,ds,plr) if v.Parent ~= plr.Accessories then local hasGot = Instance.new("BoolValue") hasGot.Name = "HasGotItem" hasGot.Parent = v if ds ~= nil then hasGot.Value = (ds:GetAsync(hasGot.Parent.Name.."HasGot") ~= nil) and ds:GetAsync(hasGot.Parent.Name.."HasGot") or false hasGot.Changed:connect(function() ds:UpdateAsync(hasGot.Parent.Name.."HasGot",function() return hasGot.Value end) end) end end end end function createFolder(plr,parent,ds) if parent:IsA("Folder") then local pClone = parent:Clone() pClone.Parent = plr clearAllValues(pClone,ds,plr) end end game.Players.PlayerAdded:connect(function(plr) local ds = (game:GetRemoteBuildMode()) and nil or game:GetService("DataStoreService"):GetDataStore("Stats",tostring(plr.userId)) local stats = Instance.new("Folder",plr) stats.Name = "PlayerStats" local egg_bucks = Instance.new("IntValue",stats) local basketlevel = Instance.new("IntValue",stats) local currentRoundEggs = Instance.new("IntValue",stats) local introDone = Instance.new("BoolValue",stats) local tutorialDone = Instance.new("BoolValue",stats) local inGame = Instance.new("BoolValue",stats) local changing = Instance.new("BoolValue",stats) local playing = Instance.new("BoolValue",stats) introDone.Name = "IntroDone" tutorialDone.Name = "TutDone" currentRoundEggs.Name = "CurrentEggSpace" egg_bucks.Name = "Eggs" basketlevel.Name = "BasketLevel" inGame.Name = "InGame" changing.Name = "IsChanging" playing.Name = "IsPlaying" coroutine.resume(coroutine.create(function() createFolder(plr,rs.Accessories,ds) end)) local torsocolor = BrickColor.Random() plr.CharacterAdded:connect(function(char) plr:ClearCharacterAppearance() local bodyColors = Instance.new("BodyColors",char) bodyColors.TorsoColor = torsocolor local shirt = Instance.new("ShirtGraphic",char) shirt.Graphic = "rbxassetid://180484140" char.Humanoid.Died:connect(function() if inGame.Value == true then egg_bucks.Value = (plr.Accessories.Perks["Double Eggs"].HasGotItem.Value ~= true) and egg_bucks.Value + currentRoundEggs.Value or egg_bucks.Value + (currentRoundEggs.Value * 2) currentRoundEggs.Value = 0 inGame.Value = false end changing.Value = false plr.PlayerGui.GameHUD.HUDType.Value = "Intro" end) coroutine.resume(coroutine.create(function() while inGame.Value == false and changing.Value == false do wait() if tutorialDone.Value == true then char.Humanoid.WalkSpeed = 32 else char.Humanoid.WalkSpeed = 0 end end end)) end) if ds ~= nil then print("We're online!") egg_bucks.Value = (ds:GetAsync(egg_bucks.Name) ~= nil) and ds:GetAsync(egg_bucks.Name) or 0 basketlevel.Value = (ds:GetAsync(basketlevel.Name) ~= nil) and ds:GetAsync(basketlevel.Name) or 1 tutorialDone.Value = (ds:GetAsync(tutorialDone.Name) ~= nil) and ds:GetAsync(tutorialDone.Name) or false egg_bucks.Changed:connect(function() ds:UpdateAsync(egg_bucks.Name,function() return egg_bucks.Value end) end) basketlevel.Changed:connect(function() ds:UpdateAsync(basketlevel.Name,function() return basketlevel.Value end) end) tutorialDone.Changed:connect(function() ds:UpdateAsync(tutorialDone.Name,function() return tutorialDone.Value end) end) end end)