Mouse.Target wont see local character

Here you see I am printing everything it points at yes yes but it literally wont print the parts inside the local character… help?

Mouse.Move:connect(function()
print(mouse.Target.Name)
end)
1 Like

I think that’s intentional, you’ll need to use raycasting I think if you want to register local character parts

2 Likes

As @Acreol said, this is intended behavior and you’ll need to raycast. The wiki has plenty of tutorials on such subject, but here’s a quick snippet that’ll do what you’re intending it to:

local UserInputService = game:GetService("UserInputService")
local Workspace = game:GetService("Workspace")

local Camera = Workspace.CurrentCamera

local function CastMouse()
	local position = UserInputService:GetMouseLocation()
	local ray = Camera:ViewportPointToRay(position.X, position.Y)
	
	return Workspace:FindPartOnRay(
		-- Camera:ViewportPointToRay returns a ray with a
		-- length of 1, so we'll have to reconstruct it
		
		Ray.new(ray.Origin, ray.Direction * 1000)
	)
end

UserInputService.InputChanged:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseMovement then
		local target = CastMouse()
		
		-- Mouse.Move logic would go here
		
		if target then
			print(target.Name)
		end
	end
end)

Raycasting: How it Works
Raycasting: Making a Laser Gun

6 Likes

Did you ever find a solution.

Thank you that really helped :smiley:

1 Like

Don’t forget to mark their post as the solution if it solved your problem.

1 Like