Attempted to index nil with 'character'

im trying to make a gui button that equips a shirt on the player that presses it

serverscript:

 local click = script.Parent
 local ID = script.Parent.ID.Value
 click.MouseButton1Click:Connect(function(player)
 	if player.Character:FindFirstChild("Shirt") ~= nil then
		player.Character.Shirt.ShirtTemplate = ID
	else
 		local Shirt = Instance.new("Shirt",player.Character)
 	Shirt.ShirtTemplate = ID
 	end
end)

error:

Attempted to index nil with ‘character’

ui buttons dont return the player as a variable

doesnt work i get this error:

 MouseClick is not a valid member of TextButton "Players.123wolfyking.PlayerGui.Ownershirt.Frame.TextButton"

I didnt read ur message properlly I edited it back

MouseButton1click is the correct way to do it instead of MouseClick

No he did make it right, I thought he was using a clickdetector instead of a ui button so I told him to change it. mb