I am trying to determine if a player is on the point by seeing if their x and z cordinates are in the point, but I am getting the error
ServerScriptService.Main:6: attempt to compare boolean < number - Server - Main:6
local point1 = workspace.thePoint1
local point2 = workspace.thePoint2
local playersInHill = {}
function getPlayersOnPoint(player)
if player.Character then
if point2.Position.X < player.Character.HumanoidRootPart.Position.X < point1.Position.X and point1.Position.Z < player.Character.HumanoidRootPart.Position.Z < point2.Position.Z and player.Character.Humanoid.Health > 0 then -- THIS LINE
table.insert(playersInHill, player.Name)
end
end
end
while true do
playersInHill = nil
for index, player in pairs(game.Players:GetPlayers()) do
getPlayersOnPoint(player)
end
print(playersInHill)
task.wait(2)
end
That’s now how logical expressions work. Lua evaluates those one by one in a specific order. So what’s happening is that it’s first evaluating the leftmost portion point2.Position.X < player.Character.HumanoidRootPart.Position.X which becomes a boolean (it’s either true or false). Then it evaluates right side BOOLEAN < point1.Position.X. That’s what the error is talking about. You’ll have to split each inequality into a separate expression.
Also pro-tip, alias the Position Vector3s so there’s less clutter in your code, saving you time and effort.
function getPlayersOnPoint(player)
local p1 = point1.Position
local p2 = point2.Position
local char = player.Character
if char then
local pos = char.HumanoidRootPart.Position
if (p2.X < pos.X and pos.X < p1.X) and (p1.Z < pos.Z and pos.Z < p2.Z) and char.Humanoid.Health > 0 then
table.insert(playersInHill, player.Name)
end
end
end