I can't tell if the datastores having issues saving or neither of them are working some help on making this work would be appreciated.


local dss = game:GetService("DataStoreService")
local dsm = dss:GetDataStore("TestingData55553".."Data")





local function tableconvert(folddata)
	if folddata then
		local tabledata = {}
		local function search(val,data)
			for i,v in pairs(val:GetChildren()) do
				if not game:GetService("CollectionService"):HasTag(v,"DoNotSave") then
					if v.ClassName == "InvtValue" or v.ClassName == "BoolValue" or v.ClassName == "NumberValue" or v.ClassName == "StringValue" then
						data[v.Name] = v.Value
					elseif v.ClassName == "Color3Value" then
						data[v.Name] = {}
						data[v.Name].r = v.Value.r 
						data[v.Name].g = v.Value.g 
						data[v.Name].b = v.Value.b 
					elseif v.ClassName == "Vector3Value" then
						data[v.Name] = {}
						data[v.Name].X	= v.Value.X
						data[v.Name].Y = v.Value.Y
						data[v.Name].Z= v.Value.Z		
					elseif v.ClassName == "DoubleConstrainedValue" or v.ClassName == "IntConstrainedValue" then
						data[v.Name] = {}
						data[v.Name].MinValue= v.MinValue
						data[v.Name].Value = v.Value
						data[v.Name].MaxValue = v.MaxValue			
					elseif v.ClassName == "BrickColorValue" then
						data[v.Name] = v.Value.Name	
					elseif v.ClassName == "Folder" then
						data[v.Name] = {}
						search(v,data[v.Name])
					end
				end
			end
		end
		search(folddata,tabledata)
		return tabledata
	end
	return nil
end

local function save(plr,foldata)
	local worked, output
	for i = 1,10 do
		worked,output = pcall(function()
			if plr ~= nil and foldata ~= nil then
				local playerUserId = game.Players:GetUserIdFromNameAsync(plr.Name)
				dsm:SetAysnc(playerUserId,foldata)
			end
		end)
		if not worked then
			wait(1)
		else
			break		
		end
		
	end
end

local function add(plr,folddata)
	local playerUserId = game.Players:GetUserIdFromNameAsync(plr.Name)
	local dt = dsm:GetAsync(playerUserId)
	if dt ~= nil then
		local function search(ob,dt)
			if type(dt) == "table" then
				for i,v in pairs(dt) do
					if ob:FindFirstChild(i) == nil then
						local placehold
						if type(v) == "number" then
							placehold = "NumberValue"
						elseif type(v) == "boolean" then
							placehold = "BoolValue"
						elseif type(v) == "string" then
							placehold = "StringValue"	
						elseif type(v) == "table" then
							if v.Z ~= nil then
								placehold = "Vector3Value"
							elseif v.g ~= nil then
								placehold = "Color3Value"
							elseif v.MaxValue ~= nil then
								placehold = "DoubleConstrainedValue"
							elseif v.BrickColor ~= nil then
								placehold = "BrickColorValue"
							end
						end
						if placehold ~= nil then
							local new = Instance.new(placehold)
							new.Name = i
							new.Parent = ob
						end
					end
					if ob[i].ClassName == "IntValue" or ob[i].ClassName == "NumberValue" or ob[i].ClassName == "BoolValue" or (ob[i].ClassName == "StringValue" and type(v) == "string") then
						ob[i].Value = v
					elseif ob[i].ClassName == "DoubleConstrainedValue" or ob[i].ClassName == "IntConstrainedValue" then
						ob[i].MaxValue = v.MaxValue
						ob[i].MinValue = v.MinValue
						ob[i].Value = v.Value
					elseif ob[i].ClassName == "Vector3Value" then
						ob[i].Value = Vector3.new(v.X,v.Y,v.Z)
					elseif ob[i].ClassName == "BrickColorValue" then
						ob[i].Value = BrickColor.new(v.BrickColor)
					elseif ob[i].ClassName == "Color3Value" then
						ob[i].Value = Color3.new(v.r,v.g,v.b)
					else
						search(ob[i],v)
					end
				end
			end
		end
		if dt == nil then
			local folder = Instance.new("Folder",game.ServerStorage.Datas)
			folder.Name = plr.Name
		end
		search(folddata,dt)
	end
	return folddata
end


local savetable = {}

game.Players.PlayerAdded:Connect(function(plr)
	
	local datafolder = script.Temp:Clone()
	datafolder.Parent = plr
	datafolder.Name = "Data"
	
	local worked, output = pcall(function () add(plr,datafolder) end)
	
	if not worked then	
		--blame nindo
	else
		savetable[plr.Name] = plr
		local loadedfold = Instance.new("Folder",plr)
		loadedfold.Name = "Success"
		game:GetService("CollectionService"):AddTag(loadedfold,"DoNotSave")
	end
	
end)


game.Players.PlayerRemoving:Connect(function(plr)
	if savetable[plr.Name] then
		savetable[plr.Name] = nil
		local dt = tableconvert(v.Data)
		save(plr,dt)
	end
end)


game:BindToClose(function()
	for i,v in pairs(game.Players:GetChildren()) do
		if v:findFirstChild("InCombat") then
			v.InCombat.Value = 0
		end
		v:Kick("Shutdown")
	end
	wait(5)
end)

spawn(function()
	while true do 
		wait(60)
		for i,v in pairs(savetable) do
			local dt = tableconvert(v.Data)
			save(v,dt)
		end
	end
end)