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)
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)
game.Players.PlayerAdded:Connect(function(player)
while wait(60) do
player:WaitForChild("leaderstats").Minutos.Value += 1
player:WaitForChild("leaderstats").Suricoins.Value += 1
end
end)
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)