Help with ray cast

Hey, I’ve been working on a project and ran into an issue here with ray casts.

Script
repeat
    local raycastParams = RaycastParams.new()
    raycastParams.FilterDescendantsInstances = {script.Parent, script.Parent.End, script.Parent.start, script.Parent.Parent, script.Parent.Parent.Arm, script.Parent.Parent.Base, script.Parent.Parent.MeshPart}
    raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
    local ray = workspace:Raycast(script.Parent.Position, 100*(script.Parent.End.Position - script.Parent.start.Position).Unit, raycastParams)
    if ray then
        print(ray.Instance.Name, ray.Instance.Position)
        script.Parent.End.Position = ray.Instance.Position
        task.wait(1)
    end
    task.wait()
until false

image

Initial:

Final:

Output:

it keeps printing the last output even if the part is not in the way.

If you still haven’t go the issue, the End attachment’s position is not the same as object’s position, it prints 9 or 11 but it moves to 500 in Y axis.

Any help would be appreciated :smiley:

It’s not clear what your goal is but I assume you want to have spotlight go towards that object in the image?

If you’re working with a start and end for raycasting in the same object, shouldn’t the end attachment be in a different object? Make sure your ray’s direction is correct, since you could have the attachments in fact be very close but because you only care about the unit vector, it wouldn’t be clear after multiplying 100 on it.