My Data Won't Save!

Hello, for whatever reason, no data saves when the player leaves. Any ideas? I am new to datastores and using UpdateAsync().

local DataStoreService = game:GetService(“DataStoreService”)
local CashSave = DataStoreService:GetDataStore(“Cash”)
local WinsSave = DataStoreService:GetDataStore(“Wins”)

game.Players.PlayerAdded:Connect(function(player)
local Folder = Instance.new(“Folder”)
Folder.Name = “leaderstats”
Folder.Parent = player

local CashValue = Instance.new("NumberValue")
CashValue.Name = "Cash"
CashValue.Parent = Folder
CashValue.Value = CashSave:GetAsync(player.UserId)

local WinsValue = Instance.new("NumberValue")
WinsValue.Name = "Wins"
WinsValue.Parent = Folder
WinsValue.Value = WinsSave:GetAsync(player.UserId)

end)

game.Players.PlayerRemoving:Connect(function(player)
CashSave:UpdateAsync(player.UserId , function(test)
test = player.leaderstats.Cash.Value
end)

WinsSave:UpdateAsync(player.UserId , function(test)
	test = player.leaderstats.Cash.Value
end)

end)

You need to return test on the UpdateAsync call, (you should handle that call better anyways)

What you’re doing here is pretty much pointless. You should save your data in a table with a value that you compare to see if it’s the one you loaded with, etc.

1 Like

why would you reply then lmao?