Monster Ai help needed

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

You’re trying to multiply a ray against a number, also use workspace:RayCast instead of Ray.new and FindPartOnRay.

According to the error, I believe you cannot perform “multiplication” (mul) on the ray and number.

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?

After debugging it quickly, it was just that the ) was in the wrong spot

1 Like

1: have you set the MonsterRootPart variable equal to the monster’s primary part?
2: Is goal referenced in the script yet? If so, is it a part?

Those both are deprecated and should not be used

WorldRoot:Raycast() is not deprecated. FindPartOnRay and findPartOnRay are.