So I have a datastore and leaderboard script with three different stats in it and one of them has a space in it, how would I save that? Because with what I have, whenever I join in the game, edit the stats, then leave and rejoin the stats don't save, so maybe its the third stat?
local DS = game:GetService("DataStoreService") game.Players.PlayerAdded:connect(function(plr) local ls = Instance.new("Folder",plr) ls.Name = "leaderstats" local cash = Instance.new("NumberValue", ls) cash.Name = "Cash" local rank = Instance.new("StringValue", ls) rank.Name = "Rank" local blocksm = Instance.new("NumberValue", ls) blocksm.Name = "Blocks Mined" local id = plr.userId cash.Value = DS:GetDataStore("cash"):GetAsync(id) or 0 rank.Value = DS:GetDataStore("ranks"):GetAsync(id) or "Beginner Miner" blocksm.Value = DS:GetDataStore("blocksm"):GetAsync(id) or 0 end) game.Players.PlayerRemoving:connect(function(plr) local id = plr.userId local ls = plr:FindFirstChild("leaderstats") if ls and id then DS:GetDataStore("cash"):SetAsync(id, ls.Cash.Value) DS:GetDataStore("ranks"):SetAsync(id, ls.Rank.Value) DS:GetDataStore("blocksm"):SetAsync(id, ls.BlocksMined.Value) end end)
My game is FE.
There are two methods for gettings an objects child if the child's name has a space in it.
Method 1:
Parent:FindFirstChild("Child With Spaces")
Method 2:
Parent["Child With Spaces"]
With this, this:
DS:GetDataStore("child with space"):SetAsync(id, ls.child with space.Value)
would correctly be:
DS:GetDataStore("child with space"):SetAsync(id, ls["child with space"].Value)
or
DS:GetDataStore("child with space"):SetAsync(id, ls:FindFirstChild("child with space").Value)
P.S. Make sure to also save on game.BindToClose