Datastore Not Saving

Okay, I remade my Datastore since others said it was pointless, this is from YouTube and still doesn’t save. Any issues?
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 Cash = Instance.new("NumberValue")
Cash.Name = "Cash"
Cash.Parent = Folder

local Wins = Instance.new("NumberValue")
Wins.Name = "Wins"
Wins.Parent = Folder

local CashV
local WinsV

local s , e = pcall(function()
	CashV = CashSave:GetAsync(player.UserId)
end)

if s then
	Cash.Value = CashV
else
	warn(e)
end
wait()
local ss , ee = pcall(function()
	WinsV = WinsSave:GetAsync(player.UserId)
end)

if ss then
	Wins.Value = WinsV
else
	warn(ee)
end

end)

game.Players.PlayerRemoving:Connect(function(player)
local s , e = pcall(function()
CashSave:SetAsync(player.UserId , player.leaderstats.Cash.Value)
end)

if s then
	print("Saved!")
else
	warn(e)
end
wait()
local ss , ee = pcall(function()
	WinsSave:SetAsync(player.UserId , player.leaderstats.Wins.Value)
end)

if ss then
	print("Saved!")
else
	warn(ee)
end

end)

Is it I have 2 different datastores in 1 script?

I am releasing a game May 5th and sadly I may have to delay it due to it not saving.

local DataStoreService = game:GetService("DataStoreService")
local DataStats = DataStoreService:GetDataStore("Stats")

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

local Cash = Instance.new("NumberValue")
Cash.Name = "Cash"
Cash.Parent = Folder

local Wins = Instance.new("NumberValue")
Wins.Name = "Wins"
Wins.Parent = Folder

local GetData

local s , e = pcall(function()
	GetData = DataStats:GetAsync(player.UserId)
end)

if s then
	Cash.Value = GetData.Cash
    Wins.Value = GetData.Wins
else
	warn(e)
end

game.Players.PlayerRemoving:Connect(function(player)
    local SaveData = {
        Cash = player.leaderstats.Cash.Value;
        Wins = player.leaderstats.Wins.Value;
}
    local s , e = pcall(function()
         CashSave:SetAsync(player.UserId , SaveData)
    end)

    if s then
	    print("Saved!")
    else
	    warn(e)
    end
 
end)

I’d recommend putting multiple values in a Dictionary so that it’s easier to save data that way, also can you check your Output?

2 Likes

Gonna sound weird but I was wondering that too. The output displays nothing so I guess no errors but somehow doesn’t save.

Thanks so much for the help! I have been struggling with datastores for a long time.

1 Like