There seems to be an issue in the lens, since you have said you had other lenses that work (assuming they are also AF-P). Could see if the connectors are working correctly and are clean (check the camera’s as well).
Does the manual focus work at all? The AF-P lenses use a fly-by-wire system for the manual focusing, so if that does work, then it is likely the camera and/or lens has manual focus set, and the lens is communicationg to and from the camera, and the focus motor is working.