Ray intersections acting weird

I have no idea why this isn’t detecting in front of the part. I am trying to make a script where a part shoots out another part then that part will reflect depending on if the ray hits something and the ray reflects. The intersection position for the first ray result is good:
Screenshot 2021-05-18 004913
As you can see it perfectly intersects and reflects on the surface.
The second intersection though, does not reflect on the surface the ray was hit on. Instead, it reflects inside the part.
Screenshot 2021-05-16 005925
Or rather it intersects behind it. Isn’t it supposed to be in front of the part its hitting. Also ignore the ray that is going in a straight line it doesn’t have to do anything with it. I also changed up the reflect formula a little bit. One thing I realized when learning these reflects is that you can create different formulas and get different results.
Script

local start = game.Workspace.Start

local function createPart()
	--Creating part
	local off = CFrame.new(0,0,-1.5)
	local part = Instance.new("Part",workspace)
	part.Name = "Pea"
	part.Size = Vector3.new(1,1,2)
	--part.Transparency = 1
	part.BrickColor = BrickColor.Green()
	part.Anchored = true
	part.CFrame = start.CFrame:ToWorldSpace(off)
	return part
end

local function createNewParams(table)
	--Raycast Params
	local params = RaycastParams.new()
	params.FilterDescendantsInstances = table
	params.FilterType = Enum.RaycastFilterType.Blacklist
	return params
end

local function reflect(v,n)
	local reflection = v - 2 * v:Dot(n) * n
	return reflection
end

local function drawray(origin,direction,tableList)
	local mid = origin+direction/2
	local part = Instance.new("Part",workspace)
	--part.Transparency = 1
	part.Anchored = true
	part.BrickColor = BrickColor.Red()
	part.Material = Enum.Material.Neon
	part.Size = Vector3.new(0.1,0.1,direction.Magnitude)
	part.CFrame = CFrame.new(mid,origin)
	table.insert(tableList,part)
	return part
end

local function bounce(part,raypart)
	part.Orientation = raypart.Orientation
	part.CFrame = part.CFrame - raypart.CFrame.LookVector
end

local function castRay(part,table)
	--Casts ray for part only
	local origin = part.Position
	local direction = part.CFrame.LookVector * 1.25
	
	--Creating parameters,drawing and casting ray
	local params = createNewParams(table)
	local result = workspace:Raycast(origin,direction,params)
	--local rayPart = drawray(origin,direction,table)
	return result
end

function checkRay(part,table)
	local result = castRay(part,table)
	if result then
		print(result.Instance)
		local n = result.Normal
		local x = result.Position

		local reflection = reflect(x,n)
		local newVector = x + reflection

	--Creating parameters
		local newParams = createNewParams(table)
		local newRayPart = drawray(x,newVector,table)
			
		if result then
			for i = 1,10,0.01 do
				bounce(part,newRayPart)
				checkRay(part,table)
				wait()
			end
		elseif not result then
			print("No wall has hit this ray")
			return false
		end
	end
end

local function shoot(part,table)
	for i = 1,50,1 do
		part.CFrame = part.CFrame + Vector3.new(0,0,1)
		checkRay(part,table)
		wait()
	end
end

local function main()
	local part = createPart()
	if part then
		local listToBeIgnored = {part,start}
		shoot(part,listToBeIgnored)
	end
end

main()

If you want to test this out, all you need it a part called start put it in the workspace and have a couple of walls by it so it can reflect it. This is probably the only I have with this script, idk if this is something I can control or if it is just roblox ray detection system acting weird.

Ok, so, copied the script, created the Start part and two walls and played and nothing.
I am trying to adjust the locations of the items in workspace so a reflection can take place where I can see it.
I have failed so far so if you have any insights into this I am happy to continue.

Is the part not being created or something? Or it’s not moving?

Pea is at -6.2,16.728,38.58
Start is at -6.194,0.5,-11.417
Wall1 is at -14.796,4.942,2.518
Wall2 is at -14.788,4.936,-22.587
Player is at 0,3,0
Pea is not moving

Try running it. I can’t try to fix it now since I am at school

Ok, I will play around with it and let you know what happens.

Ok, I have not solved the problem but made some progress and will continue but thought I would let you know my approach so you have a way to proceed.
I started off with checking if the Pea part was created and where it was positioned in relation to the Start part.
I did that by commenting out the call to Shoot in main.
I was not sure where you expected it to be but by experiment I believe you wanted it above and just behind (z direction) the Start part.
Having got that sorted out I started looking at the Raycast.
I noticed in the castRay function you had a call to drawray commented out so I uncommented it and saw a red ray.
I saw that there was a call to drawray in checkray so wondered why I did not see the red ray before so altered the drawray to accept a color parameter and set that to blue for castRay and red for checkRay.
I only saw a blue ray so something is still not working in the checkRay function.
I also noted that the ray was horizontal which was not as expected.
I will try some more tomorrow.

I know the problem. I was visualizing the rays and it seems like the detection was hitting behind the part because the when the part reflected, the ray was still being created at its look vector