At least when I last tried it, the OpenPeripheral sensor had a "getPlayerNames" function and a "getPlayerData" function. Or was it the CCSensors one? OpenCCSensors? Hard to tell, can't remember, and I gather the former has been known to interfere with the latter(s). In any case, the first function gives a list of players, and the second - if passed a player name - either returns the desired data, or if the player isn't in range, nil. As opposed to generating an error, which seems silly.
If you're not seeing such an alternative, then you could always
pcall "getPlayerByName":
local ok, player = pcall( p.getPlayerByName, playerName )
if ok then
-- do stuff with "player"
end
Edited by Bomb Bloke, 08 November 2015 - 12:27 PM.