I was wondering what could be wrong with this direction and raycast. No errors to the console just not going in the right direction.
local origin = ShootPart.Position
local direction = (mousepos.Position - origin).Unit * Tool.Range.Value
local rayresult = game.Workspace:Raycast(origin, direction,raycastParams)
Did you debug the origin and the direction variables to check if they are correct? You would do that with for example inserting parts at the position of the origin and direction.