Hello. Recently i have been experiencing more troubles with datasave (again). When i leave the game when the value has changed it does not save. If anyone has a new system i could use tell me but here is the script:
local DataStore = game:GetService("DataStoreService"):GetDataStore("MainCarDataStore") game.Players.PlayerAdded:Connect(function(plr) local CamaroOwned = Instance.new('BoolValue',plr) CamaroOwned.Name = "CamaroSSOwned" local LamOwned = Instance.new('BoolValue',plr) LamOwned.Name = "LamborghiniOwned" local Audi4Owned = Instance.new("BoolValue",plr) Audi4Owned.Name = "AudiA4Owned" local One1Owned = Instance.new("BoolValue",plr) One1Owned.Name = "One1Owned" local LamHurAc = Instance.new("BoolValue",plr) LamHurAc.Name = "LamborghiniHuracanAccess" local Fiat500Own = Instance.new("BoolValue",plr) Fiat500Own.Name = "Fiat500Owned" local TeslaMSOwn = Instance.new("BoolValue",plr) TeslaMSOwn.Name = "TeslaModelSOwned" local AudiTTRoadOwn = Instance.new("BoolValue",plr) AudiTTRoadOwn.Name = "AudiTTRoadsterOwned" local NissanGTROwn = Instance.new("BoolValue",plr) NissanGTROwn.Name = "NissanGTROwned" local AudiR8Own = Instance.new("BoolValue",plr) AudiR8Own.Name = "AudiR8Owned" local BugattiVeyOwn = Instance.new("BoolValue",plr) BugattiVeyOwn.Name = "BugattiVeyronOwned" local Porsche911Own = Instance.new("BoolValue",plr) Porsche911Own.Name = "Porsche911Owned" local FordTransitOwn = Instance.new("BoolValue",plr) FordTransitOwn.Name = "FordTransitVanOwned" local AudiS5Own = Instance.new("BoolValue",plr) AudiS5Own.Name = "AudiS5Owned" local ID = "CarsOwned-"..plr.UserId local savedData = nil pcall(function() savedData = DataStore:GetAsync(ID) end) if savedData ~= nil then CamaroOwned.Value = savedData[1] LamOwned.Value = savedData[2] Audi4Owned.Value = savedData[3] One1Owned.Value = savedData[4] LamHurAc.Value = savedData[5] Fiat500Own.Value = savedData[6] TeslaMSOwn.Value = savedData[7] AudiTTRoadOwn.Value = savedData[8] NissanGTROwn.Value = savedData[9] AudiR8Own.Value = savedData[10] BugattiVeyOwn.Value = savedData[11] Porsche911Own.Value = savedData[12] FordTransitOwn.Value = savedData[13] AudiS5Own.Value = savedData[14] print("Data Loaded for") else CamaroOwned.Value = false LamOwned.Value = false Audi4Owned.Value = false One1Owned.Value = false LamHurAc.Value = false Fiat500Own.Value = false TeslaMSOwn.Value = false AudiTTRoadOwn.Value = false NissanGTROwn.Value = false AudiR8Own.Value = false BugattiVeyOwn.Value = false Porsche911Own.Value = false FordTransitOwn.Value = false AudiS5Own.Value = false end end) game.Players.PlayerRemoving:Connect(function(plr) local ID = "CarsOwned-"..plr.UserId local ValuesToSave = { plr.CamaroSSOwned.Value, plr.LamborghiniOwned.Value, plr.AudiA4Owned.Value, plr.One1Owned.Value, plr.LamborghiniHuracanAccess.Value, plr.Fiat500Owned.Value, plr.TeslaModelSOwned.Value, plr.AudiTTRoadsterOwned.Value, plr.NissanGTROwned.Value, plr.AudiR8Owned.Value, plr.BugattiVeyronOwned.Value, plr.Porsche911Owned.Value, plr.FordTransitVanOwned.Value, plr.AudiS5Owned.Value } DataStore:SetAsync(ID, ValuesToSave) end) game:BindToClose(function() wait(9) for i, player in pairs(game.Players:GetPlayers()) do if player then player:Kick("This game is shutting down") end end end)
That was the script that does not save. Please help i have worked for so long trying to fix it! Please help!
you have to add a wait() between lines 3 and 4 to give the game time for the player to load in