I am trying to learn about the DataStores and "leaderstats" and a part of that is saving values when the player is quitting the game, so i created a simple script that prints out when the player leaves the value of his "Cash" (a instance inside of the player inside of the leaderstats folder). The problem is it always prints Zero and idunno why. Here is the code and a screenshot of my workspace, thanks for the help guys <3
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Value = 0
cash.Parent = leaderstats
end)
players.PlayerRemoving:Connect(function(player)
local playerStatsFolder = player:FindFirstChild("leaderstats")
local cash = playerStatsFolder:FindFirstChild("Cash")
print("Cash of " .. player.Name .. " is " .. cash.Value)
end)