why does the local CarsDataSave is printing like this
local DataStoreService = game:GetService("DataStoreService")
local WesgrinDataStore = DataStoreService:GetDataStore("MyWesgrinDataAtore")
StarterMoney = 500000000
game.Players.PlayerAdded:Connect(function(player)
local SaveData = Instance.new("Folder",player)
SaveData.Name = "SaveData"
local CarsFolder = Instance.new("Folder",game.ReplicatedStorage)
CarsFolder.Name = player.Name.."CarsData"
for i, v in pairs(game.ReplicatedStorage.CarList:GetChildren()) do
local ManufactureFolder = v:Clone()
ManufactureFolder.Parent = CarsFolder
for i2, Cars in pairs(ManufactureFolder:GetChildren()) do
Cars:Destroy()
end
for i2, Cars in pairs(v:GetChildren()) do
local CarsValue = Instance.new("BoolValue", ManufactureFolder)
CarsValue.Name = Cars.Name
CarsValue.Value = false
end
end
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
local NValur = Instance.new("IntValue",leaderstats)
NValur.Name = "Cash"
NValur.Value = StarterMoney
local PlayerID = player.UserId.."Wesgrin"
local data = WesgrinDataStore:GetAsync(PlayerID.."Data")
local carsdata = WesgrinDataStore:GetAsync(PlayerID.."CarsData")
if data then
NValur.Value = data["CashValue"]
else
NValur.Value = StarterMoney
end
if carsdata then
local CarsSave = carsdata["CarsSave"]
print(CarsSave)
for i, v in pairs(CarsFolder:GetChildren()) do
for i2, CarsValue in pairs(v:GetChildren()) do
CarsValue.Value = CarsSave[CarsValue.Name]
end
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local DataSave = {
CashValue = player.leaderstats.Cash.Value;
}
local CarsDataSave = {}
--for i, Cars in pairs(game.ReplicatedStorage[player.Name.."CarsData"]:GetChildren()) do
--table.insert(CarsDataSave, Cars)
--end
for i, v in pairs(game.ReplicatedStorage[player.Name.."CarsData"]:GetChildren()) do
for i2, Cars in pairs(v:GetChildren()) do
CarsDataSave[Cars] = Cars.Value
end
end
print(CarsDataSave)
game.ReplicatedStorage[player.Name.."CarsData"]:Destroy()
local PlayerID = player.UserId.."Wesgrin"
local success, err = pcall(function()
WesgrinDataStore:SetAsync(PlayerID.."Data", DataSave)
WesgrinDataStore:SetAsync(PlayerID.."CarsData", CarsDataSave)
end)
if success then
print("your savedata success")
else
print("your savedata unsaved")
end
end)