Problem
- The problem is I had old datastore, but it was really bad, cause was using 4 datastores to save all the data.
- I tried to load old data, to new datastore, but the problem is it detects when there’s old data for player, but isn’t loading the data for player (I tested it)
Script
Stats Script
local http = game:GetService("HttpService")
local datastore = game:GetService("DataStoreService")
local database = datastore:GetDataStore("Stats_Database_1")
local oldCrateDatabase = datastore:GetDataStore("Crate_DataStore_1")
local oldCoinsDatabase = datastore:GetDataStore("CoinsDataStoreSaveHmmCuzWhyNot")
local oldRobuxDatabase = datastore:GetDataStore("RobuxDataStore_3")
local oldStageDatabase = datastore:GetDataStore("StageDataLOL")
local plrs = game:GetService("Players")
local function saveData(plr)
local success, errormessage = pcall(function()
database:SetAsync(plr.UserId, {coins = plr.Coins.Value; robux = plr.RobuxDonated.Value; crates = plr.CratesOpened.Value; stage = plr.leaderstats.Stage.Value})
end)
if success then
print("Saved all stats for "..plr.Name.."!")
else
print("Failed to save all stats for "..plr.Name.."!")
end
end
local function getData(plr)
local playerStats
local oldStats = {coins = nil; crates = nil; robux = nil; stage = nil;}
local success, errormessage = pcall(function()
playerStats = database:GetAsync(plr.UserId)
end)
if success and playerStats then
print("Loaded all stats for "..plr.Name.."!")
plr.Coins.Value = playerStats.coins
plr.RobuxDonated.Value = playerStats.robux
plr.CratesOpened.Value = playerStats.crates
plr:WaitForChild("leaderstats").Stage.Value = playerStats.stage
elseif not errormessage then
oldStats.coins = oldCoinsDatabase:GetAsync(plr.UserId, "-coins")
oldStats.crates = oldCrateDatabase:GetAsync(plr.UserId, "-crates")
oldStats.robux = oldRobuxDatabase:GetAsync(plr.UserId, "-robux")
oldStats.stage = oldCoinsDatabase:GetAsync(plr.UserId)
wait()
plr.Coins.Value = oldStats.coins
plr.RobuxDonated.Value = oldStats.robux
plr.CratesOpened.Value = oldStats.crates
plr.leaderstats.Stage.Value = oldStats.stage
wait(10)
oldCoinsDatabase:RemoveAsync(plr.UserId, "-coins")
oldCrateDatabase:RemoveAsync(plr.UserId, "-crates")
oldRobuxDatabase:RemoveAsync(plr.UserId, "-robux")
oldCoinsDatabase:RemoveAsync(plr.UserId)
print("Loading old data for "..plr.Name.."!")
else
print("Failed to load all stats for "..plr.Name.."!")
end
end
plrs.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local crates = Instance.new("NumberValue")
crates.Name = "CratesOpened"
crates.Parent = plr
local rs = Instance.new("NumberValue")
rs.Name = "RobuxDonated"
rs.Parent = plr
local coins = Instance.new("NumberValue")
coins.Name = "Coins"
coins.Parent = plr
local stage = Instance.new("NumberValue")
stage.Name = "Stage"
stage.Parent = leaderstats
getData(plr)
end)
plrs.PlayerRemoving:Connect(function(plr)
saveData(plr)
end)
game:BindToClose(function()
for _, v in pairs(plrs:GetChildren()) do
saveData(v)
end
end)
Thanks for your help! ![]()