How to make player only face horizontally and vertically

trying to make it so players can only face horizontally and vertically (ex: pressing w makes faces forward, s = back, a = left, d = right)