I cant cast rays for mobile. Please help me

Heres my problem. I am trying to cast a ray in the center of the screen on mobile. For a gun. When I aim it something the gun shoots and a beam appears.
When the gun is not aiming at anything the beam does not appear or in different solutions I tried just goes to position 0,0,0.
When I try teleporting myself to the offset position in a test it does work, but when I try casting a ray with it nothing comes out.
I am trying to do something like the game Iron Sights made by Wolfpaq. Its an old mobile fps game.

if UserInputService.TouchEnabled == true or UserInputService.KeyboardEnabled == false then
				--[[local MobileRayPosition = Camera:ScreenPointToRay(Crosshair.ImageLabel.AbsolutePosition.X, Crosshair.ImageLabel.AbsolutePosition.Y) 
				local MobileRay = workspace:Raycast(Camera.CFrame.Position, MobileRayPosition.Direction * 5000 ,RayParams)
				local P
			
				if MobileRay then
					 P = MobileRay.Position
				else
					local PointCFrame = Camera.CFrame.Position + MobileRayPosition.Direction * 2000
					P = PointCFrame
				end]]--
			local ViewPortRayParams = RaycastParams.new()
			ViewPortRayParams.FilterType = Enum.RaycastFilterType.Blacklist
			ViewPortRayParams.FilterDescendantsInstances = {Player.Character}
			
			local camera = workspace.CurrentCamera
			local viewportPoint = camera.ViewportSize / 2
			local unitRay = camera:ViewportPointToRay(viewportPoint.X, viewportPoint.Y, 0)
			local ViewPortRay = workspace:Raycast(unitRay.Origin, unitRay.Direction * 5000, ViewPortRayParams )
			local rayPos = nil
			
			if ViewPortRay then
				if ViewPortRay.Position then
					rayPos = ViewPortRay.Position
					CastRay(rayPos)
				else
					--[[local Direction = unitRay.Origin + unitRay.Direction * 2040
					local P = Direction
					rayPos = unitRay.Origin + Direction * 2040
					print(unitRay.Origin)
					print(unitRay.Direction)]]--
					local rayPos = Camera.CFrame.Position + (Camera.CFrame.LookVector * 2000)
					print(Camera.CFrame.Position)
					print(unitRay.Direction)
					
					CastRay(rayPos)
				end
			else
				--[[local Direction = unitRay.Origin + unitRay.Direction * 2040
				local P = Direction
				print(unitRay.Origin)
				print(unitRay.Direction)
				rayPos = unitRay.Origin + Direction * 2040]]--
				local rayPos = Camera.CFrame.Position + (Camera.CFrame.LookVector * 2000)
				print(Camera.CFrame.Position)
				print(unitRay.Direction)
				
				CastRay(rayPos)
			end