I've recently been working a game that needed a smarter AI, and the only one I could find has one function that always errors for me, even though I directly copied it after it errored the first time, it still errors though
this is a normal script in a model in the workspace
function CheckSight(target)
local ray = Ray.new(MyRoot.Position, (target.Position - MyRoot.Position).Unit * 40)
local hit,position = workspace:FindPartOnRayWithIgnoreList(ray, (script.Parent))
if hit then
if hit:IsADescendentOf(target.Parent) and math.abs(hit.Position.Y - MyRoot.Position.Y) < 2 then
print("visible")
return true
end
end
return false
end
it always says "unable to cast object to value", but it worked just fine for the guy who made the original script.
so if anyone has any idea why its erroring, please tell me, I'm trying to have the game out this year (bad idea, but it was my brother's idea not mine)
