Adding Currency Problem

here is the new script:

local dataservice = game:GetService("DataStoreService")
local statsstore = dataservice:GetDataStore("StatsData")
local oldtime = dataservice:GetDataStore("DsTime")
local oldsuricoins = dataservice:GetDataStore("SaveData")

game.Players.PlayerAdded:Connect(function(player)
	local statstable = statsstore:GetAsync(player.UserId) or {}
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local cash = Instance.new("IntValue")
	cash.Name = "Suricoins"
	cash.Value =  statstable.Suricoins or oldsuricoins:GetAsync("id_"..player.UserId) or 0
	cash.Parent = leaderstats
	
	local Time = Instance.new("IntValue")
	Time.Name = "Minutos"
	Time.Value = statstable.Minutos or oldtime:GetAsync(player.UserId.."-tim") or 0
	Time.Parent = leaderstats
	while wait(60) do
		Time.Value += 1
		cash.Value += 100
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local stats = {
		["Suricoins"] = player.leaderstats.Suricoins.Value,
		["Minutos"] = player.leaderstats.Minutos.Value
	}
	statsstore:SetAsync(player.UserId, stats)
end)

game:BindToClose(function()
	for i,v in pairs(game.Players:GetChildren()) do
		local stats = {
			["Suricoins"] = v.leaderstats.Suricoins.Value,
			["Minutos"] = v.leaderstats.Minutos.Value
		}
		statsstore:SetAsync(v.UserId, stats)
	end
end)

this should work for getting old data and eventually starting to replace it.
just finished adding the function. It should work now.

1 Like