Help with raycast (Not ignoring parts)

I’m trying to make a simple raycast for shooting a beam, but when you aim it at yourself or at buildings, it starts to glitch out, sometimes inverting itself and going backwards when you aim it at yourself.

When shooting the beam, the raycast glitches out if you aim it at yourself, I want for it to go through the character instead of going backwards or causing the character to start to spin around rapidly.

I could not find anything regarding this issue on the dev forum, so I have resorted to trying to print the ignorelist, to try to see if maybe nothing was being put into it, but there was clearly stuff being put into it, it just wasn’t being ignored. I have also tried using roblox’s deprecated raycast incase it broke, but the only thing that helped with was ensuring that if you shoot the beam into the sky, it doesn’t go a super far distance away.

            local IgnoreList = {}
			local Island = workspace.island

			for i, v in pairs(Island:GetDescendants()) do
				if v:IsA("BasePart") and v.Transparency == 1 then
					table.insert(IgnoreList, v)
				end
				if v:IsA("BasePart") and v.CanCollide == false then
					table.insert(IgnoreList,v)
				end
			end

			for i,v in pairs(char:GetDescendants()) do
				if v:IsA("BasePart") then
					table.insert(IgnoreList,v)
				end
			end
			
			print(IgnoreList)
			
			local raycastOrigin = char:WaitForChild("Meshes/untitled1").Position
			local rayDirection = (Mouse.Hit.p - raycastOrigin).Unit * 150
			local Params = RaycastParams.new()
			Params.FilterType = Enum.RaycastFilterType.Exclude
			Params.FilterDescendantsInstances = IgnoreList

			local result = workspace:Raycast(raycastOrigin, rayDirection, Params)

			if result then
				script.FireAttack:FireServer(Key, "BeamPos", CFrame.new(result.Position))
				Atomic.Point.CFrame = CFrame.new(result.Position)
				Root.CFrame = Root.CFrame:Lerp(CFrame.new(Root.CFrame.Position, Vector3.new(result.Position.X, Root.CFrame.Position.Y, result.Position.Z)), 0.5)
			else
				local ray = Ray.new(char["Meshes/untitled1"].Position, (Mouse.Hit.p - char["Meshes/untitled1"].Position).Unit * 150)
				local hit,pos,surface = workspace:FindPartOnRayWithIgnoreList(ray, {char, Light})
				script.FireAttack:FireServer(Key, "BeamPos", CFrame.new(pos))
				Atomic.Point.Position = pos
				Root.CFrame = Root.CFrame:Lerp(CFrame.new(Root.CFrame.p, Vector3.new(pos.X, Root.CFrame.p.Y, pos.Z)), 0.5)
			end

Any help would be greatly appreciated!

I had this problem too but I’m not sure how I fixed it. I think I switched setting the FilterType and FilterDescendantsInstances so the FilterType comes first and that fixed it for some reason.

Well in my script, FilterType already comes first, so that could not fix this issue.

I ment the other way around so FilterType comes after.

That did not fix it.
I’m still unsure as to what is going on.

Maybe the parts are not being added to the table. Does the island consist of meshes or unions?

Meshes only, but it is already going into the IgnoreTable, as I saw when I printed it.