Why isn't my raycast pointing in the right direction?

My goal is to make the grandma shoot you once you cross the line/beam. The raycast origin point is the grandma’s HumanoidRootPart and the raydirection is pointing towards the attachment at the end of the beam.

For some reason, the raycast goes off to the side, which is clearly not in the direction of the end attachment. I also put a wall that is supposed to be detected by the raycast. Here is a video demonstration (sorry i had to upload it to youtube since the video file was too big)

The script is supposed to print the name of anything hit by the raycast. Notice how it doesn’t detect the wall which is between the grandma and the end attachment. When I walk over to the side, it will detect me and shoot me, which is not even close to where the end attachment is.

Why is this happening? Am I doing something wrong? Please note that I am completely new to raycasting and I just started learning about them yesterday

Please provide the code in here so we can view it easier.

Still it looks like you’re trying to raycast from a point to a point, but raycast takes a direction as a second paramater.

The code is shown in the video, but here’s the code:

local debounce = true

local raycast = Ray.new(script.Parent.Attachment1.WorldPosition,script.Parent.Attachment2.WorldPosition)

while wait(0) do 
	
	local hit = game.Workspace:FindPartOnRayWithIgnoreList(raycast,{script.Parent})
	if hit then
		print(hit.Name)
		if game.Players:GetPlayerFromCharacter(hit.Parent) then
			debounce = false
			hit.Parent.Humanoid:TakeDamage(50)
			script.Parent["Light Machine Gun Fire"]:Play()

			script.Parent.Beam.Enabled = false
			wait(1)
			script.Parent["Pistol Reload"]:Play()
			wait(2)
			script.Parent.Beam.Enabled = true
			debounce = true
		end
	end
end

Awesome, so here you go, try this out

local raycast = Ray.new(script.Parent.Attachment1.WorldPosition,script.Parent.Attachment2.WorldPosition-script.Parent.Attachment1.WorldPosition)

Since it takes a direction, not a point, if we take the point and minus the starting point, it should give us a direction that we can give to the raycast system