GetAsync returns nil, and nil

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

Be able to get two tables saved via SetAsync.

  1. What is the issue? Include screenshots / videos if possible!

GetAsync returns nil on both attempts in the script below, but SetAsync seems to work as the if success statement runs and prints out the two tables that were saved.

The GetAsync Portion
Runs when player joins the game.

function PlayerJoined(Player)

	local success = nil
	local ModelData = nil
	local playerData = nil
	local attempt = 1

	repeat
		
		success, ModelData = pcall(function()
			ModelStore:GetAsync(Player.UserId.."WpnModel")
		end)
		
		success1, playerData = pcall(function()
			PlayerData:GetAsync(Player.UserId.."MeisterData")
		end)
		
		attempt += 1

		if not success or success1 then
			warn(ModelData)
			warn(playerData)
			task.wait(1)
		end

	until success and success1 or attempt == 5
	
	if success and success1 then
		
		if not ModelData or playerData then
			print("No data found", ModelData, playerData)
		elseif ModelData and playerData then
			HasPlayed:InvokeClient(Player,ModelData, playerData)
			print("Successfully Loaded Existing Data")
		end
	end
end

The SetAsync Portion
Runs when Remote is fired.

function SaveCharModel(Player)

	local UserID = Player.UserId


	print("New Weapon for", Player.Name)
	local WpnModel = game.Workspace.Map.Start:WaitForChild("WeaponModel"):Clone()
	WpnModel.Name = UserID.."WeaponModel"
	local ModelData = {
		["ModelName"] = WpnModel.Name,
		["WeaponName"] = RealResult,
		["ShirtId"] = WpnModel.Shirt.ShirtTemplate,
		["PantsId"] = WpnModel.Pants.PantsTemplate,
		["FaceId"] = WpnModel.Head.Face.Texture,
		
		["SkinColor"] ={ 
			R = WpnModel.Torso.Color.R,
			G = WpnModel.Torso.Color.G,
			B = WpnModel.Torso.Color.B,
		},
		
		["HairColor1"] = {
			R = CurrentColor.R,
			G = CurrentColor.G,
			B = CurrentColor.B
		},
		
		["HairColor2"] = {
			R = CurrentColor2.R,
			G = CurrentColor2.G,
			B = CurrentColor2.B
		},
		
		["AccessoryNumber"] = AccessoryNumber,
		["Hair1"] = HairNumber1,
		["Hair2"] = HairNumber2,
	}

	
	local playerData = {
		
		["Money"] = 0, 
		
	}
	local success = nil
	local errorMsg = nil
	local attempt = 1

	repeat
		success, errorMsg = pcall(function()
			ModelStore:SetAsync(Player.UserId.."WpnModel", ModelData)
		end)
		
		success1, errorMsg = pcall(function()
			PlayerData:SetAsync(Player.UserId.."MeisterData", playerData)
		end)
		
		attempt += 1

		if not success and success1 then
			warn(errorMsg)
			task.wait(1)
		end

	until success and success1 or attempt == 5

	if success and success1 then
		print ("New Saved", ModelData, playerData)
	else
		print("Unable to save for".. Player.Name)
	end

end
1 Like

In a pcall the order for the variables is:

	success, errormessage = pcall(function()

You were setting the errormessage variable to your data variable, and since the pcall’s success is true there is no error, aka nil.

make your pcall with a new variable called “error” or whatever you want and have the getasync set the value of you playerdata inside of the pcall:
example

local playerData  = nil
local success1, errormessage = nil, nil
success1, errormessage = pcall(function()
	playerData  = PlayerData:GetAsync(Player.UserId.."MeisterData")
end)
print(playerData)
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.