Unable to cast Ray to Vector3

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

Hi! I’m trying to make a pathfinding monster that will chase the player if it sees them. However, I’ve encountered an error.

  1. What is the issue? Include screenshots / videos if possible!

I have a line of code:

local hit, pos = workspace:Raycast(ray, npc)

However, after the NPC pausing its movement and refusing to continue, I checked output to find:

Unable to cast Ray to Vector3  -  Server

This occurs as soon as the player comes into the NPC’s line of sight.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

After checking both the DevForum for already posted solutions, and the Developer Hub for any help (i.e. checking if code I was using was deprecated), I came out empty handed.

Any help would be greatly appreciated, thanks!

workspace:Raycast() accepts 3 parameters: rayOrigin, rayDirection, and raycastParams. If you use the following line of code, your problem should be fixed:

local params = RaycastParams.new()
params.FilterDescendantsInstances = {npc}
params.FilterType = Enum.RaycastFilterType.Exclude
local hit, pos = workspace:Raycast(ray.Origin, ray.Direction, params)

That seems to have fixed the problem, thank you!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.