I’ve been getting this error when trying to run the script below.
Players.PizzaArmy333.PlayerScripts.Hitbox:43: attempt to compare Vector2 <= Vector2
That’s not the real problem, the real problem is how do I see if the spot the NPC needs to move to is under or equal to the max movement distance? I need a way to check if the distance is valid on line 43
The script (Local script in StarterPlayerScripts)
local units = game.Workspace.Units:GetChildren()
local move = game.ReplicatedStorage.Remotes.Move
local selected = false
for _, unit in ipairs(units) do
if unit:IsA("Model") and unit:FindFirstChildWhichIsA("Model") then
local char = unit:FindFirstChildWhichIsA("Model")
local hitbox = char:WaitForChild("Hitbox")
local click = hitbox:WaitForChild("ClickDetector")
local data = unit:FindFirstChild("Data")
if click and data then
click.MouseHoverEnter:Connect(function(plr)
data.Extra.SelectionBox.Visible = true
end)
click.MouseHoverLeave:Connect(function(plr)
if selected == false then
data.Extra.SelectionBox.Visible = false
end
end)
click.MouseClick:Connect(function(plr)
selected = not selected
data.Extra.SelectionBox.Visible = true
end)
local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Button1Down:Connect(function()
if mouse.Target.Parent.Name == "Tiles" and mouse.Target:IsA("MeshPart") then
local targetTile = mouse.Target
local targetCords = targetTile:GetAttribute("Cords")
local currentTile = data.CurrentTile
local currentCords = currentTile:GetAttribute("Cords")
--TODO move to server script
local maxMove = data:GetAttribute("MoveRange")
if targetCords <= maxMove and data.Owner.Value == game.Players.LocalPlayer.Name then
char.HumanoidRootPart.Position = targetTile.Position + Vector3.new(0, 0.65, 0)
end
end
end)
end
end
end
A custom Vector2 coordinates system is used for each tile.
I can provide more info (screenshots etc) of any more information you need. Thank you!
CurrentTile is a value set to default of the square under it specifically, and the script is trying to get CurrentCords from an attribute in the CurrentTile