Mouse.Target ignoring certain models?

Hi, I am making a game that relies on you clicking on parts, and hovering over them.

I have come to the issue that Mouse.Target doesn’t detect or just ignores my models.

The script I wrote:

local plr = game:GetService("Players").LocalPlayer
local mouse = plr:GetMouse()
local harvestgui = script.Parent.Harvest

mouse.Move:Connect(function()
	if mouse.Target then
		print(mouse.Target.Name)
		if mouse.Target:HasTag("Harvestable") then
			print("harvestable")
			harvestgui.Visible = true
			harvestgui.Position = UDim2.new(0,mouse.X + 10, 0,mouse.Y+ 10)
		else
			harvestgui.Visible = false
			harvestgui.Position = UDim2.new(0,0,0,0)
		end
	end
end)

print(mouse.Target.Name)

^^ This for some reason, prints out the part UNDER my model.
If I make a part that is way smaller than my model, it still detects it. I also added a part that is the size of the entire model, into the model, and it still ignores it.

Please help, as this is breaking my game.

1 Like

Mouse.Target doesn’t detect models but the parts inside the models. You could try checking the parent of the object that mouse.target returned if they are the model you are looking for.

if Mouse.Target:FindFirstAncestorWhichIsA("Model") then

end
1 Like

No, the model is located on the baseplate. The script doesn’t detect ANY parts in the model, it just says ‘Baseplate’ when I hover my mouse over the model.

Ah, I see. So do you mean whenever you move your mouse, it just prints “Baseplate” constantly?

1 Like

Yes. (dmsajkghdusaighdajskidhsakdj)

Hmm… I looked up online and your camera FOV could be causing this. Do your camera FOV set to a different value?

1 Like

My camera is about 100 studs away, and the FOV is the regular, however, I think we are close to solving the problem, since I do manipulate the camera. Could it have something to do with CameraType?

Nevermind, I playtested without manipulating the camera, and this still occurs. Even when I am 2 studs away.

Hmm… I see. Maybe you could use UserInputService:GetMouseLocation() and then transform it to 3d point and shoot a raycast to that point.

I did try your script though and there was no problem with it.

1 Like

off topic but i wish we could blacklist certain folders/models from Mouse.Target!

1 Like

I found something very weird, I added this line into my code:

mouse.TargetFilter = nil

This works, even though I never set a filter for the mouse. So I guess this is the solution, very strange.

1 Like

Mouse.Targetfilter exists to blacklist models from mouse.target

Yes, but I don’t believe it takes multiple instances. Just one unfortunately

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.