Help me with Raycasting into the sky!

I am using a custom mouse position script that I made using popular methods, and I try to return a RaycastResult, but whenever I click the sky it returns nil as expected.

How can I make it return the position including the Exlude list I made but when I click the sky it will just return the position I clicked with the maximum distance.

local ClientModule = {}

ClientModule.MouseCast = function(Camera, Mouse, Params)
	if Params == nil then
		Params = RaycastParams.new()
	end
	local unitRay = Camera:ScreenPointToRay(Mouse.X, Mouse.Y)
	local Raycast = workspace:Raycast(unitRay.Origin, unitRay.Direction * 500, Params)
	if Raycast then
		return Raycast
	else
		-- Return the position with the max 500 unit distance.
		return unitRay.Origin + unitRay.Direction * 500 -- I can do this but this will not use the raycast params...
	end 
end

return ClientModule

Try just adding , Params to then end of the return. It should be like this:

unitRay.Origin + unitRay.Direction * 500, Params

There is no way I can use the Params in the other script that uses Raycast.Position, which returns nil if I click the sky… and that’s unfortunate.
I try to make it so if I click nothing it will still fire a ray with a limit of the provided range, this example is that I shoot a fireball projectile and when I press it again it fires onto the location of the fireball, I want it to ignore the fireball and cast the position that I click similar to Mouse.TargetFilter.

You can try Params.FilterDescendantsInstances to filter out objects. It should look something like this:

Params.FilterDescendantsInstances = {} -- Put anything you want to exclude in this list
Params.FilterType = Enum.RaycastFilterType.Exclude

If it returns nil you have the direction you want to shoot, so then just vector normalize that. With the vector normalized you can then scale it to however you want but you have the direction and then you can just fire a fireball that way.