Saving stats error

I have this script I got from a Youtube Tutorial that should save the players stats. For some reason it’s not. Any ideas?
Script -

local dss = game:GetService("DataStoreService")

local ds = dss:GetDataStore("data")


function saveData(plr)


	local cash = plr.Currency.Coins.Value

	pcall(function()

		ds:SetAsync(plr.UserId .. "-Coins", cash)
	end)
end



game.Players.PlayerAdded:Connect(function(plr)


	local ls = Instance.new("Folder")
	ls.Name = "Currency"
	ls.Parent = plr

	local cash = Instance.new("IntValue")
	cash.Name = "Coins"
	cash.Parent = ls


	local data = nil

	pcall(function()

		data = ds:GetAsync(plr.UserId .. "-Coins")
	end)

	cash.Value = data or 0
end)


game.Players.PlayerRemoving:Connect(saveData)

game:BindToClose(function()


	for i, plr in pairs(game.Players:GetPlayers()) do

		saveData(plr)
	end
end)

At first, are you testing it in studio? At second, do it print any error?

I advise you to test it in Roblox in itself, and not in the studio, it is not saved there for some reason, secondly, I advise you to watch this videos

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.