So, i made this AI script using two other AI scripts and kind of trying to make them work together.
It should work all fine (Or at least i think so) but i get this error at line 25:
Workspace.Monster.AiScript:25: attempt to perform arithmetic (mul) on Ray and number
I don’t know how to fix this, so how could I?
Ai script (function of where it errors out)
local function CheckMonsterSight(Target)
local ray = Ray.new(MonsterRootPart.Position, (Target.Position - MonsterRootPart.Position)).Unit * 40
local Hit,Position = workspace:FindPartOnRayWithIgnoreList(ray, {script.Parent})
if Hit then
if Hit:IsDescendantOf(Target.Parent) and math.abs(Hit.Position.Y - MonsterRootPart.Position.Y) > 3 then
print("I can see the target")
return true
end
end
return false
end
The local ray variables is causing the problem.
Also, if you are presenting lines of code, can you explain it? I’m still learning
It was actually just because one of the ) was in the wrong spot
Anyway, another bug came up with a different function
bug error: Workspace.Monster.AiScript:19: attempt to index nil with ‘Position’
Code:
local function GetingWaypointPath(Goal)
local PathfindingService = game:GetService("PathfindingService")
local pathParams = {
["AgentHeight"] = 8,
["AgentRadius"] = 3,
["AgentCanJump"] = false
}
local path = PathfindingService:CreatePath(pathParams)
path:ComputeAsync(MonsterRootPart.Position, Goal.Position)
return path
end
I’ve seen this code work with one of the other AI’s, so is there a reason for this to be happening?