Hello This Is My Second Post Here I Would Like To Ask Why This Error Comes Up When I Try To Add Or Save The value "cash" Here Is My Code :
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("DataStore")
game.Players.PlayerAdded:Connect(function(player)
local stats = Instance.new("Folder")
stats.Name = "leaderstats"
local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Value = 100
cash.Parent = stats
stats.Parent = player
local data
local success,errorMessage = pcall(function()
data = DataStore:GetAsync(player.UserId.."-cash")
end)
if success then
cash.Value = data
else
warn("There Was An Error Whilst Fetching Data. Cause: "..errorMessage.."")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success,errorMessage = pcall(function()
DataStore:SetAsync(player.UserId.."-cash",player.leaderstats.cash.Value)
end)
if success then
print("Data Successfully Saved")
else
print("There Was An Error When Saving Data!")
warn(errorMessage)
end
end)

4 comments
Parent the stats folder to the player, add "stats.Parent = players" on line 8. Add [Solved] to the title if this solved your problem.
^Yes
how do i change the title
There should be an edit button somewhere next to it.