hi, need some help figuring out these functions for my other system, but they seem to be faulty and idk how to implement it otherwise 
local mouse = game.Players.LocalPlayer:GetMouse()
local rs = game:GetService("RunService")
local function PointWithinArea(Point, Points)
local Side
for i = 1, #Points do
local Point0 = Points[i].Position
local Point1 = Points[i == #Points and 1 or i + 1].Position
local Value = (Point1 - Point0):Cross(Point - Point0).Y > 0
if Side ~= nil and Value ~= Side then
return false
end
Side = Value
end
return true
end
function isPointInPolygon(x, y, poly)
-- poly is a Lua list of pairs like {x1, y1, x2, y2, ... xn, yn}
local x1, y1, x2, y2
local len = #poly
x2, y2 = poly[len - 1], poly[len]
local wn = 0
for idx = 1, len, 2 do
x1, y1 = x2, y2
x2, y2 = poly[idx], poly[idx + 1]
if y1 > y then
if (y2 <= y) and (x1 - x) * (y2 - y) < (x2 - x) * (y1 - y) then
wn = wn + 1
end
else
if (y2 > y) and (x1 - x) * (y2 - y) > (x2 - x) * (y1 - y) then
wn = wn - 1
end
end
end
return wn % 2 ~= 0 -- even/odd rule
end
local function unwrapper(tbl)
local new = {}
for i,v in pairs(tbl) do
v = v.Position
table.insert(new,v.X)
table.insert(new,v.Z)
end
return new
end
rs.RenderStepped:Connect(function()
for i,v in pairs(workspace.polys:GetChildren()) do
for i,part in pairs(v:GetChildren()) do
part.Color = isPointInPolygon(mouse.Hit.Position.X,mouse.Hit.Position.Z,unwrapper(v:GetChildren())) and Color3.new(0.384314, 1, 0) or Color3.new(1, 0, 0)
end
end
end)
^
as you can see, it only works for the quad.
both functions do the same, i just wanted to try them both.
any help is appreciated!