Why is this Datastore no longer working as intended?

For some reason my Datastore is not Getting Async which means it’s not loading the player’s items. Why is the if statement returning false for?

I made a comment on the if statement near the bottom of the script.

     --} Reference services:

local RS = game:GetService("ReplicatedStorage");
local DSS = game:GetService("DataStoreService");
local P = game:GetService("Players");
local hatShop = RS:WaitForChild("HatShop")
local hatShopItem = hatShop:WaitForChild("ShopItem")

local remotes = RS:WaitForChild("RemoteFunctions")
local datastoreRemote = remotes:WaitForChild("Datastore")
local storedHats = {}

--} Reference variables:

local bytes = {
 {97, 122}; --! a-z:
 {65, 90}; --! A-Z:
 {48, 57}; --! 0-9:
};

local overwrite = true;

local vault = DSS:GetDataStore("Test");

--} Reference functions:

function GetRandomCharacter()
 local charset = bytes[math.random(1, 3)];
 return string.char(math.random(charset[1], charset[2]));
end;

function GenerateID(len)
 local id;
 for i = 1, len do
  local char = GetRandomCharacter();
  if not id then
   id = char;
  else
   id = id .. char;
  end;
 end;

 return id;
end;

function saveHats(plr, uid)
	local hats = plr:WaitForChild("Hats");
	
	local hatKeys = {}
	if #hats:GetChildren() > 0 then
		for i,v in next, hats:GetChildren() do
			hatKeys[GenerateID(20)] = v.Name;
		end;
	end;
end;

function loadHats(plr, uid)
	local hats = plr:WaitForChild("Hats");
	
	for i, v in next, vault:GetAsync(uid) do
		for x, y in next, hatShopItem:GetChildren() do
			if v == y.Name then
				y:Clone().Parent = hats;
			end;
		end;
	end;
end;

function SaveData(plr, uid)
 local pack = plr:WaitForChild("Backpack");
 local gear = plr:WaitForChild("StarterGear");
 
 
 
 local keys = {};
 if #gear:GetChildren() > 0 then
  for i, v in next, gear:GetChildren() do
   keys[GenerateID(20)] = v.Name;
  end;
end;
end;


function LoadData(plr, uid)
 local pack = plr:WaitForChild("Backpack");
 local gear = plr:WaitForChild("StarterGear");
 local hats = plr:WaitForChild("Hats");

 for i, v in next, vault:GetAsync(uid) do
  for x, y in next, RS:GetChildren() do
   if v == y.Name then
    y:Clone().Parent = pack;
    y:Clone().Parent = gear;

    

end;
  end;
 end;
end;

P.PlayerAdded:connect(function(plr)
 local uid = plr.userId;
 if vault:GetAsync(uid) then  --LINE THAT IS RETURNING FALSE
  LoadData(plr, uid);
  loadHats(plr, uid);
  print("Worked - game.Workspace.Data Store")
 else
	print("something went wrong")
  return;
 end;
end);

P.PlayerRemoving:connect(function(plr)
 local uid = plr.userId;
 if overwrite then
  SaveData(plr, uid);
  saveHats(plr, uid);
print("Hats and weapons saved!")
  
 else
  return;
 end;
end);

A post was merged into an existing topic: Can someone guide me through this Datastore?