Trying to script multiple elements for leaderstats to save through the use of a data store however, I keep coming across the same error over and over.
Here are the two scripts for the leaderstat values and the data stores. https://gyazo.com/eb8b0b6aadf9a2c4cfa7f5bb461e9ad2 https://gyazo.com/adc5b8e9b36f57286b80bcc3b64cf448
Upon playing the game only one value appears on the leaderboard. https://gyazo.com/c6194ea657384749d4b12d16381607c9
An error is returned saying leaderstats is not apart of the player. https://gyazo.com/e09c08ab446fb470c10cbc92e5c36a50
However, when checked in game leaderstats exists as part of the player. https://gyazo.com/e2ae4080484c1ece085e9bf82a9c8223
Thats my Problem too but i realize i have to put :WaitForChild("leaderstats") in every Variable for Leaderstats.
Local leaderstats = game.Players.LocalPlayer:WaitForChild("leaderstats")
You shouldn't really be using connect as its deprecated, instead, you should be using Connect. Also, you can just put everything into 1 script, instead of having 2 scripts. This is script is more efficient instead of having 2 scripts. Your problem was not having a wait() function in the 2nd script. Hope this helps!
local DataStore = game:GetService("DataStoreService") local ds = DataStore:GetDataStore("ServerSaveSystem") local Players = game:GetService("Players") Players.PlayerAdded:Connect(function(Player) local leaderstats = Instance.new("Folder") leaderstats.Parent = Player leaderstats.Name = "leaderstats" local Cash = Instance.new("IntValue") Cash.Parent = leaderstats Cash.Name = "Cash" Cash.Value = ds:GetAsync(Player.UserId) or 0 local Ore = Instance.new("IntValue") Ore.Parent = leaderstats Ore.Name = "Ore" Ore.Value = ds:GetAsync(Player.UserId) or 0 ds:SetAsync(Player.UserId, Cash.Value) ds:SetAsync(Player.UserId, Ore.Value) Cash.Changed:Connect(function() ds:SetAsync(Player.UserId, Cash.Value) Ore.Changed:Connect(function() ds:SetAsync(Player.UserId, Ore.Value) end) end) end) Players.PlayerRemoving:Connect(function(Player) ds:SetAsync(Player.UserId, Player.leaderstats.Cash.Value) ds:SetAsync(Player.UserId, Player.leaderstats.Ore.Value) end)