I'm new to Data Store2 (I've learned about it yesterday), but how do I convert a Data Store that saves tools and numbers into a data store 2?


And before you report this question as non-constructive, I have tried several times. I've already undone the script so I can't copy and paste it here.


Here is my current data store:

local GameDataStore = game:GetService("DataStoreService"):GetDataStore("GameDataStore")

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Votes = ReplicatedStorage:WaitForChild("VotesEnableDisable")

game:GetService("Players").PlayerAdded:Connect(function(Player)
	game:GetService("ReplicatedStorage").PlayerAdded:FireAllClients()
	
	Player.CharacterAdded:Connect(function(Character)
		Character.Humanoid.Died:Connect(function()
			ReplicatedStorage.PlayerDied:FireAllClients(Player.Name)
		end)
	end)	
	
	local Leaderstats = Instance.new("Folder")
	Leaderstats.Name = "leaderstats"
	Leaderstats.Parent = Player
	
	local Wins = Instance.new("IntValue")
	Wins.Name = "Wins"
	Wins.Parent = Leaderstats
	
	local InRound = Instance.new("BoolValue")
	InRound.Name = "InRound"
	InRound.Parent = Player
	
	local Afk = Instance.new("BoolValue")
	Afk.Name = "Afk"
	Afk.Parent = Player
	
	local Key = "player_" .. Player.UserId
	
	local Data
	
	local Success, ErrorMessage = pcall(function()
		Data = GameDataStore:GetAsync(Key)
	end)
	
	if Success then
		if Data then
			Wins.Value = Data.Leaderstats.Wins
			
			if Data.ToolNames then
				for _, ToolName in pairs(Data.ToolNames) do
					local Tool = game:GetService("ServerStorage")[ToolName]
					
					Tool:Clone().Parent = Player.StarterGear
					Tool:Clone().Parent = Player.Backpack
				end
			end
		end
	else
		warn("Unable to load " .. Player.Name .. "'s" .. " data: " .. ErrorMessage)
	end
end)

game:GetService("Players").PlayerRemoving:Connect(function(Player)
	game:GetService("ReplicatedStorage").PlayerRemoving:FireAllClients(Player.Name)
	
	local Key = "player_" .. Player.UserId
	
	local DataStore = {
		Leaderstats = {
			Wins = Player.leaderstats.Wins.Value
		},
			
		ToolNames = {}
	}
	
	for i, Tool in pairs(Player.StarterGear:GetChildren()) do
		table.insert(DataStore.ToolNames, i, Tool.Name)
	end
	
	local Success, ErrorMessage = pcall(function()
		GameDataStore:SetAsync(Key, DataStore)
	end)	
	
	if not Success then
		warn("Unable to save " .. Player.Name .. "'s" .. " data: " .. ErrorMessage)
	end
end)

game:BindToClose(function()
	if game:GetService("RunService"):IsStudio() then
		return
	end
	
	for _, Player in pairs(game:GetService("Players"):GetPlayers()) do
		local Key = "player_" .. Player.UserId
		
		local DataStore = {
			Leaderstats = {
				Wins = Player.leaderstats.Wins.Value
			},
			
			ToolNames = {}

		}
		
		for i, Tool in pairs(Player.StarterGear:GetChildren()) do
			table.insert(DataStore.ToolNames, i, Tool.Name)
		end
		
		local Success, ErrorMessage = pcall(function()
			GameDataStore:SetAsync(Key, DataStore)
		end)	
		
		if not Success then
			warn("Unable to save " .. Player.Name .. "'s" .. " data: " .. ErrorMessage)
		end		
	end
end)

Thank you for your time.

3 comments

5

How are you an Expert again?

1

lol

0

(I think)You can't convert a DataStore to DataStore2. May be you can transfer the data from DS to DS2.