Hello , i got a warning from console , i dont know why and please help me because i supposed to public the game today . pls help me
local DataStoreService = game:GetService("DataStoreService")
local oldDataStore = DataStoreService:GetDataStore("DataSaver001") -- money DATA
local playerData = DataStoreService:GetDataStore("PlayerData") -- Vehicle DATA
local helmetData = DataStoreService:GetDataStore("Helmet") -- Helmet DATA
local newDataStore = require(script.DataStore2)
newDataStore.Combine("DataSaver001", "PlayerData") -- combining it
--- MONEY FUNCTION OK
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
-- MOTOR FUNCTION #1
local function CreateCarValue(player, name, value)
local carValue = player.OwnedCars:FindFirstChild(name)
if not carValue then
carValue = Instance.new("BoolValue")
carValue.Name = name
carValue.Parent = player.OwnedCars
end
carValue.Value = value
return carValue
end
--MOTOR FUNCTION #2 -- MOTOR TABLE
local function CreateTable(player)
local playerStats = {}
for _, stat in pairs(player.OwnedCars:GetChildren()) do
if stat.Value == true then
playerStats[stat.Name] = true
end
end
return playerStats
end
-- MOTOR FUNCTION #3
local cars = {
-- list cars put here ok
"HondeEX5",
"HondeWave100",
"Kasaki 150sp",
"Lagenda115zr",
"Lajak",
"Rzx Milinium",
"Wave125i Drag",
"Light Lz",
"Yamha Soleriz",
"Yamha 125rz",
"Sniper150Drag",
"Yamha Sniper135 v1",
"Honde Deo",
"Honde Nsr500",
"Icikiwir",
"Yamha Yzr500",
"Honde Wave 125r",
"Kasaki Pdk R1",
"Dukatti SuperSport S",
"Kasaki Serpico",
"Yamha X1r",
"Vesp 150ss",
"Dukatti 1299",
"Yamha Sniper v2",
"Suzuka Raider 150",
"Kasaki Ninja H2",
"Yamha R6 v2",
"Suzuka Hayabusa Drag",
"Yamha X1r White",
"Mz Agusza F4",
"Honde NR750",
"Dukatti 1199 Martini"
}
local function onPlayerJoin(player)
-- Money Section
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local money = Instance.new("IntValue")
money.Name = "Money"
money.Parent = leaderstats
--- Motor Section
local leaderstats = Instance.new("Folder")
leaderstats.Name = "OwnedCars"
leaderstats.Parent = player
--- Money Section
local MoneyStats = newDataStore("MoneyData1", player)
local data = MoneyStats:Get()
if not data then
local oldData = oldDataStore:GetAsync(player.UserId.."-Money")
print("oldData for player " .. player.Name .. ": " .. tostring(oldData))
if oldData then
data = oldData
MoneyStats:Set(data)
else
data = {Money=3000}
print(player.Name .." MONEY'S DATA not found from both data , creating a new data")
end
end
if data then
print("money loaded for " .. player.Name)
end
if type(data) == "number" then
money.Value = data
else
money.Value = data['Money']
end
money.Changed:Connect(function(value)
MoneyStats:Set(create_table(player))
end)
-- Vehicle section ( not done yet )
local MotorStats = newDataStore("VehicleData", player)
local data1 = MotorStats:Get()
if data1 then
print("Motorsikal loaded forc" .. player.Name)
for car, value in pairs(data1) do
if value == true and table.find(cars, car) then
CreateCarValue(player, car, true)
end
end
else
-- load old data
local oldmotor = playerData:GetAsync("Player_" .. player.UserId)
if oldmotor then
print("Load for player " .. player.Name)
for car, value in pairs(oldmotor) do
if value == true and table.find(cars, car) then
CreateCarValue(player, car, true)
end
end
print("Saving for player " .. player.Name)
MotorStats:Set(oldmotor)
else
print("NO DATA MOTORCYCLE FOUND FOR " .. player.Name)
end
end
end
local function onPlayerExit(player)
local player_stats = create_table(player)
local motor_stats = CreateTable(player)
local MotorStats = newDataStore("VehicleData", player)
local MoneyStats = newDataStore("MoneyData1", player)
MotorStats:Set(motor_stats)
MoneyStats:Set(player_stats)
player.leaderstats.Money.Value = player_stats.Money
print("money and motor saved for " .. player.Name)
end
game.Players.PlayerAdded:Connect(onPlayerJoin)
game.Players.PlayerRemoving:Connect(onPlayerExit)