Basically I have a script that tweens the player backward. It also cast a ray to decide the speed of the tween. It was working fine in my test game put when I moved it to my main game it works 30% of the time and the rest of the time it launches the player in the wrong direction. Can somebody please help me find the solution?

		local Distance = 30
		--Make Ray Check if there is object behind them
		local Goal = humanoidRootPart.CFrame * CFrame.new(0,0,Distance)
		local ray = Ray.new(humanoidRootPart.Position,Goal)
		local hit,Position = workspace:FindPartOnRayWithIgnoreList(ray,{humanoidRootPart.Parent,game.Workspace.Meshes,game.Workspace:FindFirstChild("Blood.Splatter.Particles")})
		local Time = 1
		if hit then
			print("Found Part in the way: " .. hit.Name)
			Goal = CFrame.new(Position)
			--Equation for speed
			Time = (Position - humanoidRootPart.Position).Magnitude * .5 / 30
			
		else
			print("No Part In the way")
			Goal = humanoidRootPart.CFrame * CFrame.new(0,0,Distance)
		end
		
		--If object behind them add debris and a sound effect when they finish tween
		humanoidRootPart.Anchored  = true
		local tweenInfo = TweenInfo.new(
			Time, -- Time
			Enum.EasingStyle.Linear, -- EasingStyle
			Enum.EasingDirection.Out, -- EasingDirection
			0, -- RepeatCount (when less than zero the tween will loop indefinitely)
			false, -- Reverses (tween will reverse once reaching it's goal)
			0 -- DelayTime
		)
				
		local tween = TweenService:Create(humanoidRootPart, tweenInfo, {CFrame = Goal})
		tween:Play()