Raycast shooting things im not even aiming at

  1. What do you want to achieve?

A FPS gun that fires where where i aim my mouse

  1. What is the issue?

The raycast doesn’t even fire near where I want it to

  1. What solutions have you tried so far?

I’ve tried looking for some Roblox raycasting guides, tried using the camera as the origin of the gun, and tried changing some position values

local shootDistance = script.Parent.MaxShootDistance.Value
local rayOrigin = gun.effectsPart.Position
local rayDirection = mouse.Hit.Position

local raycastParams = RaycastParams.new()
		raycastParams.FilterDescendantsInstances = {char}
		raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
		
		local raycastResult = workspace:Raycast(rayOrigin, (rayDirection - rayOrigin)*rayDirection, raycastParams)
		
		if raycastResult then
			local hitPart = raycastResult.Instance
			local model = hitPart:FindFirstAncestorOfClass("Model")
			print(model, hitPart)
			
			if model then
				if hitPart.Parent:FindFirstChild("Humanoid") then
					hitPart.Parent.Humanoid.Health -= script.Parent.Damage.Value
				end
			end
		end

The hitpositon does not update as you drag your mouse.

So what do you recommend to use instead?

To add to what @notMundaze said I think your RayDirection is where your mouse hits on screen, but if something is in the way your raycastResult will be whatever the ray hits, not your mouse Position.

local rayDirection = mouse.Hit.Position

This is only declared once, so the ray’s destination is constant.

Well I’m not too familiar with mouseposition but I’m pretty sure in FP the mouseposition is just the center of the screen on the 2d plane where the mouse can move.

Instead, I’d probably recommend using UIS in some way coz the mouse functions arent updated anymore and UIS has more functions.

or try playermouse, heres the API: UserInputService (roblox.com)
PlayerMouse (roblox.com)
Mouse (roblox.com)

Fixed it with this post: Making a ray from the middle of the screen with the camera of a player