Adding Currency Problem

here let me change it up. I havent done much with slowly switching datastores this way.
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 olddata = {
	["Suricoins"] = oldsuricoins:GetAsync("id_"..player.UserId),
	["Time"] = oldtime:GetAsync(player.UserId.."-tim")
	}
	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 0
	cash.Parent = leaderstats
	
	local Time = Instance.new("IntValue")
	Time.Name = "Minutos"
	Time.Value = statstable.Minutos or 0
	Time.Parent = leaderstats
	if olddata.Suricoins > 0 then
		cash.Value = olddata.Suricoins
		oldsuricoins:SetAsync("id_"..player.UserId, 0)
	end
	if olddata.Time > 0 then
		Time.Value = olddata.Time
		oldtime:SetAsync(player.UserId.."-tim", 0)
	end
	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)
1 Like

its ok, take ur time, and if i have to give manually back the minutes to everybody, its fine

game leaderboard stills at 0 - 0 and every min it doesnt add any value

You should just use DataStore2. It’s easier and more efficient, in terms of saving data.

Get the DataStore2 module here and watch a simple tutorial on it here. I’m telling you, it’s way better than normal data stores, and it’s really easy to understand.

The DataStore2 ModuleScript is a community-made creation by @Kampfkarren.

Put this into a separate script and remove the while wait do in the 1st script. Hopefully it works better:

game.Players.PlayerAdded:Connect(function(player)
while wait(60) do
player.leaderstats.Minutos.Value += 1
player.leaderstats.Suricoins.Value += 1
end
end)
1 Like

the output complains about leaderstats

it seems like there isnt a “leaderstats” folder

can you send me a screen shot?

image

image

I mean I want a screenshot of the error.

alright, do this instead:

game.Players.PlayerAdded:Connect(function(player)
while wait(60) do
player:WaitForChild("leaderstats").Minutos.Value += 1
player:WaitForChild("leaderstats").Suricoins.Value += 1
end
end)
1 Like

You dont check if the player’s datastore is nil or not. If its a new player it will error

its still the same, the output says that errror is in this line (i think)

nvm this is he leaderbaord script lol

I do indeed check it. It says or {} and later when setting the value puts or 0.

maybe we should create the leaderstats folder

there is no leaderboard actually here: image

Right there. You need to fix that part

1 Like

alright, I see what you mean let me fix it real quick.

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 oldsuricoinsv = oldsuricoins:GetAsync("id_"..player.UserId) or 0
	local oldtimev = oldtime:GetAsync(player.UserId.."-tim") or 0

	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 0
	cash.Parent = leaderstats
	
	local Time = Instance.new("IntValue")
	Time.Name = "Minutos"
	Time.Value = statstable.Minutos or 0
	Time.Parent = leaderstats
	if oldsuricoinsv > 0 then
		cash.Value = oldsuricoinsv
		oldsuricoins:SetAsync("id_"..player.UserId, 0)
	end
	if oldtimev > 0 then
		Time.Value = oldtimev
		oldtime:SetAsync(player.UserId.."-tim", 0)
	end
	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)

its fixed now

1 Like