Script not equipping shirt

So I’m trying to make a door that gives you a shirt when you walk through it, here is the code

local GroupId = 6094444

shirtid 	= "4987200326"
giveshirt 	= true

function GiveShirt(player)
	wait(.5)
	if giveshirt == true and not player.Character:FindFirstChild("Shirt") then
		local s = Instance.new("Shirt", player.Character)
		s.ShirtTemplate = "http://www.roblox.com/asset/?id="..shirtid
	else
		repeat wait() until player.Character:FindFirstChild("Shirt")
		player.Character.Shirt.ShirtTemplate = "http://www.roblox.com/asset/?id="..shirtid
	end
end

game.Workspace.GroupOnlyDoor.Touched:Connect(function(obj)
	local player = game.Players:FindFirstChild(obj.Parent.Name)
	if player then
		if player:IsInGroup(GroupId) then
			local rank = player:GetRankInGroup(GroupId)
			print(rank)
			if rank >= 4 then
				local player = game.Players:GetPlayerFromCharacter(obj.Parent)
				GiveShirt(player)
			end
		end
	end
end)

But when you walk through the door it removes your current shirt and it doesn’t load in the one I want it to. This is a group game and the shirt is owned by the group. Also, I have checked and it does set the texture id on the shirt to the correct one.

EDIT: By deletes the current shirt I mean it unloads it, it doesn’t actually delete the shirt in the player

I have had an issue like this before. I looked on the DevForum and came across this: