Hello alex i tried your script it does save but it does not load my old data , any reason?
old script as indicator
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("DataSaver001")
local Players = game:GetService("Players")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Money = Instance.new("IntValue")
Money.Name = "Money"
Money.Parent = leaderstats
local success, data = pcall(function()
return DataStore:GetAsync(player.UserId.."-Money")
end)
if success then
Money.Value = data or 3000
print(player.Name .. " has " .. Money.Value .. " money.")
else
warn("Error while loading Money data: " .. data)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, error = pcall(function()
DataStore:SetAsync(player.UserId.."-Money", player.leaderstats.Money.Value)
print(player.Name .. "'s money data saved. Current money: " .. player.leaderstats.Money.Value)
end)
if success then
print("Player data saved successfully!")
else
warn("Error while saving Money data: " .. error)
end
end)
current script ( problem )
local DataStoreService = game:GetService("DataStoreService")
local oldDataStore = DataStoreService:GetDataStore("DataSaver001")
local newDataStore = require(script.DataStore2)
newDataStore.Combine("DATA2", "player") -- better do not change DATA2 for testing only
local function create_table(player)
local player_stats = {}
for _, stat in pairs(player.leaderstats:GetChildren()) do
player_stats[stat.Name] = stat.Value
end
return player_stats
end
local function onPlayerJoin(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local money = Instance.new("IntValue")
money.Name = "Money"
money.Parent = leaderstats
local MoneyStats = newDataStore("DATA2", player)
local data = MoneyStats:Get(player.UserId.."-Money")
if not data then
local success, oldData = pcall(function()
return oldDataStore:GetAsync(player.UserId.."-Money")
end)
if success then
data = oldData or {Money=3000}
MoneyStats:Set(player.UserId.."-Money", data)
else
warn("Error stupewddd " .. oldData)
data = {Money=3000}
end
end
money.Value = data['Money']
money.Changed:Connect(function(value)
MoneyStats:Set(player.UserId.."-Money", create_table(player))
end)
end
local function onPlayerExit(player)
local player_stats = create_table(player)
local MoneyStats = newDataStore("DATA2", player)
local success, err = pcall(function()
MoneyStats:Set(player_stats)
MoneyStats:Save()
end)
if not success then
warn('Game problem lol')
end
end
let me know