Making the players mouse ignore transparent parts

I’m making a placement system for a Tower Defense game I am creating, I am trying to stop the towers from being placed on the path. This works, however, in each tower there is a transparent part that shows their range. Because of this, the tower can be placed on top of the path because the mouse.Target is touching the invisible range part.

I am unable to use mouse.TargetFilter, because I am already using it to filter out the tower I am placing.

-- Local Script

local tower = Tower:Clone()
		tower.Parent = workspace

		local placed = false

		mouse.TargetFilter = tower -- filtering out the tower being placed

		repeat
			tower:MoveTo(mouse.Hit.p)
			tower:FindFirstChildWhichIsA("Tool").Handle.Anchored = true
			
			mouse.Button1Down:Connect(function()
				if mouse.Target.Parent ~= workspace.Paths and mouse.Target.Parent ~= workspace.Waypoints then -- stopping the tower from being placed on the path
					placed = true
				end
			end)
			
			wait()
			
		until placed == true


		print(mouse.Target) -- still places because mouse.Target is the Range Part of other towers
		tower:Destroy()
		game.ReplicatedStorage.Events.PlaceTower:FireServer(Tower, mouse.Hit.p, cost) -- placing tower on server

Any help is appreciated, if I am doing something that should be changed please let me know. Many Thanks.

1 Like

Is the CanCollide property off on the transparent part? If it is, you can also turn off the CanQuery property, which basically makes your mouse unable to detect that part

Also it makes raycasts unable to detect that part too so keep that in mind

Edit: Another option you can do is make the transparent part inside of the same model or folder (although this might be annoying), TargetFilter applies for any descendants of whatever it’s equal to. So if I set the TargetFilter to a model, the mouse would ignore anything inside of the model

Thanks a ton, I simply turned off CanQuery on every Range Part and it worked. :grin:

1 Like

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