Mouse.Target isn't registering my spawn-pads


(output when I click on this blue brick below)

These are the properties of the part if they’re needed.

Not too sure if this is a building issue or a scripting one
I’m using Mouse.Target to check if the mouse is hovering over one of my vehicle spawn pads, it’s ignoring the SpawnPad and printing Terrain.

Code:

local Mouse

local function Equipped(mouse)
	Mouse = mouse
end

local function Activated()
	if Mouse then
		if Mouse.Target then
			print(Mouse.Target)
        end
    end
end

Tool.Equipped:Connect(Equipped)
Tool.Activated:Connect(Activated)

Any help is appreciated, thanks.

It’s reasons like this why I don’t typically use Mouse.Target. For the time being, you can use Mouse.TargetFilter and set it to the terrain to ignore the click.

What I typically do is make use of raycasts, since that’s essentially what both Mouse.Target and Mouse.Hit equate to internally. I use Camera.ViewportPointToRay with the position of the input (UserInputService), extend that ray then pass as many objects as I want into the ignore table. The first return of a ray function, Hit, is what I use over Mouse.Target.

5 Likes

Thank you, I’ll attempt that.

[extra]