Problem with DataStore

So im doing this lil avatar customisation system, and i ran into a problem when trying to make it save
Heres the code:

local dataStoreService = game:GetService("DataStoreService")
local players = game:GetService("Players")
local mainStore = dataStoreService:GetDataStore('Main')

players.PlayerAdded:Connect(function(plr)
	local avatar = Instance.new('Folder')
	avatar.Parent = plr
	avatar.Name = 'avatar'
	local shirt = Instance.new('StringValue')
	shirt.Parent = avatar
	shirt.Name = 'shirt'
	shirt.Value = "None"

	local pants = Instance.new('StringValue')
	pants.Parent = avatar
	pants.Name = 'pants'
	pants.Value = "None"

	local hat = Instance.new('StringValue')
	hat.Parent = avatar
	hat.Name = 'hat'
	hat.Value = "None"



	--Loading
	local success,data = pcall(function()
		return mainStore:GetAsync(plr.UserId)		
	end)
	if success then
		if not data then
			data = {"None","None","None"}
		end
		if typeof(data) ~= 'table' then
			data = {data,0}
		end

		shirt.Value = data[1]
		pants.Value = data[2]
		hat.Value = data[3]
		print(data[1])
		print(data[2])
		print(data[3])
		
		
	else
		--print("Data failure")
	end
end)






--saving
players.PlayerRemoving:Connect(function(plr)
	
	local shirt = plr:FindFirstChild("avatar"):FindFirstChild("shirt")
	local pants = plr:FindFirstChild("avatar"):FindFirstChild("pants")
	local hat = 	plr:FindFirstChild("avatar"):FindFirstChild("hat")
	print(shirt.Value)

	local success,err = pcall(function()
		return mainStore:SetAsync(plr.UserId,{shirt.Value,pants.Value,hat.Value})
		
	end)
	if not success then
		--print("ERR")
	end
end)




The shirt, pants and hat values in Player are correct, printing after leaving also works. But when i try and rejoin, this happens:


Thanks for any help!

First, put this in #help-and-feedback:scripting-support not Creation Feedback, second is the issue is that your table contains no content to load.

data[1], data[2], data[3] are most likely nil, and as such can’t be loaded.

You probably have some code that’s messing up the table, so I would recommend printing after each step in the code to properly debug exactly where the data is getting messed with.