How can I switch from DataStore to DataStore2 without losing data?

Look I recorded a video for you to see, what happens is that if I run it with the datastore 2 it doesn’t work, i.e. the data is lost :c
https://streamable.com/3bsb4l

Because you are using studio and this is DataStore2 features. Create a bool value in ServerStorage named SaveInStudio with value true

AND UPDATE THE SCRIPT BECAUSE I RECENTLY UPDATED IT (sorry) (I checked on my place and forgot to change the key “Plr_” to “Player_”)

1 Like

Uh, let me do it! ill back in a sec

It woooorks omggg thank you so much Alex! you are the best

1 Like

I have a small question, in my game I also have cars, and they have also been getting lost, will they stop getting lost?

If you replace with DataStore2, then they may stop

1 Like

That means that at this point you should stop losing cars, right? :smiley:

I’m really sorry @3YbuKtOp but the Datastore of the vehicles is not in conjunction with the normal datastore, do you think it keeps losing the cars? here I pass you the script of the ds of cars

local DataStore = game:GetService("DataStoreService"):GetDataStore("PlayerCars")
local ShopCars = game.ServerStorage:WaitForChild("ShopCars")
local AddCarEvent = game.ReplicatedStorage:WaitForChild("AddCar")
local ServerPurchasedCars = game.ServerStorage:WaitForChild("PurchasedCars")

function OnCharacterAdded(player)
	wait()
	local PurchasedCars = ServerPurchasedCars:FindFirstChild(player.Name)
	if PurchasedCars then
		local Cars = PurchasedCars:GetChildren()
		for i, v in pairs(Cars) do
			AddCarEvent:FireClient(player, v.Name)
		end
	end
end

function OnPlayerAdded(player)
	local CharacterAdded = 0
	local PurchasedCars = Instance.new("Folder", ServerPurchasedCars)
	PurchasedCars.Name = player.Name
	player.CharacterAdded:Wait()
	CharacterAdded = CharacterAdded + 1
	wait()
	
	local Data = nil
	local success, err = pcall(function()
		Data = DataStore:GetAsync(player.UserId)
	end)
		
	if Data then
		for i, v in pairs(Data) do
			if ShopCars:FindFirstChild(v) then
				local clonedCar = ShopCars:FindFirstChild(v):Clone()
				clonedCar.Parent = PurchasedCars
				AddCarEvent:FireClient(player, v)
			end
		end
	end
	if not success then
		print("There was an error while getting data of player " .. player.Name)
		warn(err)
	end
	
	player.CharacterAdded:Connect(function()
		CharacterAdded = CharacterAdded + 1
		if CharacterAdded > 1 then
			OnCharacterAdded(player)
		end
	end)
end

function OnPlayerRemoving(player)
	local Cars = {}
	local PurchasedCars = ServerPurchasedCars:FindFirstChild(player.Name)
	if PurchasedCars then
		for i, v in pairs(PurchasedCars:GetChildren()) do
			table.insert(Cars, v.Name)
		end
		local success, err = pcall(function()
			DataStore:SetAsync(player.UserId, Cars)		
		end)
		if not success then
			print("There was an error while saving data of player " .. player.Name)
			warn(err)
		end
	end
end

--game.Players.PlayerAdded:Connect(OnPlayerAdded)
--game.Players.PlayerRemoving:Connect(OnPlayerRemoving)

@3YbuKtOp sorry to bother you, seriously all this is very stressful for me and according to doctor’s orders I can not have much stress, in my previous comment I sent you the code of the ds of the cars, do you think it will stop losing the data?

I personally see no reason for it to be lost, try making a DataStore2 here

1 Like

Uh, where should I paste this? I’m getting dizzy already.

Are you sure that it is in the game that the data is lost?

1 Like

I am absolutely sure, players can enter the game and out of nowhere lose money or cars.

Do you only have 2 databases in game?

1 Like

Sorry for the late reply, I got a little dizzy so I came up for air.

I personally don’t see why this is happening. Try to do here as well as with money, transfer to DataStore2. You already have an example, if it doesn’t work out - let me know.

2 Likes

Wait i dont even know i can do kind of this thing , thx for the knowledge !

1 Like

Cars Still losing :C i think that is because roblox have an request limit look

Yes, it is, but you don’t reach it if you only use it when the player enters and leaves and you only have 2 databases, which should not cause a limit

1 Like