DataStore Not Working

I made a datastore script to save the tools and gamepasses in my game but it is not saving and the debugger isn’t showing me any errors. Did I make any mistake in the code?

local Players = game:GetService("Players")
local Datastore = game:GetService("DataStoreService"):GetDataStore("OJTDE4")
local RS = game:GetService("ReplicatedStorage")

Players.PlayerAdded:Connect(function(plr)
	local Tools = Instance.new("Folder")
	local Data = Instance.new("Folder")

	Tools.Parent = plr
	Data.Parent = plr

	local SavedData = Datastore:GetAsync(plr.UserId)

	Tools.Name = "Tools"
	Data.Name = "Data"

	if SavedData ~= nil then
		local ToolData = SavedData.ToolData
		local PlayerData = SavedData.PlayerData
		for i,v in pairs(ToolData) do
			local ToolObject = RS.Tools.Template:Clone()
			ToolObject.Name = v.Name
			ToolObject.Durability.Value = v.Durability
			ToolObject.ToolID.Value = v.ToolID			
			ToolObject.Damage.Value = v.Damage
			ToolObject.Parent = Tools
		end
		for i,v in pairs(script.Data:GetChildren()) do
			local DataValue = v:Clone()
			local DataTable = nil
			DataValue.Parent = Data
			for i,v in pairs(PlayerData) do
				if v.Name == DataValue.Name then
					DataTable = v
				end
			end
		end
	end


end)

Players.PlayerRemoving:Connect(function(plr)
	local Tools = plr.Tools
	local Data = plr.Data
	
	local ToolData = {}
	local PlayerData = {}
	
	
	for _,ToolObject in pairs(Tools:GetChildren()) do
		
		ToolData[#ToolData + 1] = {
			Name = ToolObject.Name,
			Durability = ToolObject.Durability.Value,
			ToolID = ToolObject.ToolID.Value,
			Damage = ToolObject.Damage.Value
		}
	end
	if PlayerData ~= nil then
		for _,DataValue in pairs(Data:GetChildren()) do
			PlayerData[#PlayerData + 1] = {
				Name = DataValue.Name,
				ClassName = DataValue.ClassName,
				Value = DataValue.Value
			}
		end
	else
		print("Error")
	end
	
	Datastore:SetAsync(plr.UserId, {["ToolData"] = ToolData, ["PlayerData"] = PlayerData})
	print("Data Saved")
end)


So firstly, wrap your :GetAsync() and :SetAsync() in a pcall. This will allow you to handle errors without the whole code stopping and you can also print out the error message if there is any, then let me know if you got any errors.

Okay, so I just found out that you cannot actually save instances by using DataStoreService…

What I suggest you to do is to create bool values for every tool and gamepass and if the player owns them or whatever, they would be set to true. Just save the value of the bool values.

The aim if the datastore script was to identify the duplicate tools that a player can have

How do I make a datastore that updates everytime something is added to a folder?

I’m making a game where people can buy tools and buy gamepasses.

local Players = game:GetService(“Players”)
local Datastore = game:GetService(“DataStoreService”):GetDataStore(“OJTDE4”)
local RS = game:GetService(“ReplicatedStorage”)

Players.PlayerAdded:Connect(function(plr)
local Tools = Instance.new(“Folder”)
local Data = Instance.new(“Folder”)

Tools.Parent = plr
Data.Parent = plr

local SavedData = Datastore:GetAsync(plr.UserId)

Tools.Name = "Tools"
Data.Name = "Data"

if SavedData ~= nil then
	local ToolData = SavedData.ToolData
	local PlayerData = SavedData.PlayerData
	for i,v in pairs(ToolData) do
		local ToolObject = RS.Tools.Template:Clone()
		ToolObject.Name = v.Name
		ToolObject.Durability.Value = v.Durability
		ToolObject.ToolID.Value = v.ToolID			
		ToolObject.Damage.Value = v.Damage
		ToolObject.Parent = Tools
	end
	for i,v in pairs(script.Data:GetChildren()) do
		local DataValue = v:Clone()
		local DataTable = nil
		DataValue.Parent = Data
		for i,v in pairs(PlayerData) do
			if v.Name == DataValue.Name then
				DataTable = v
			end
		end
	end
end

end)

Players.PlayerRemoving:Connect(function(plr)
local Tools = plr.Tools
local Data = plr.Data

local ToolData = {}
local PlayerData = {}


for _,ToolObject in pairs