Mouse.target is working wrong!

Well, basically, i want to fire a event when player press T and their mouse.target.name == “WellPlacement” and its distance is within 7 studs.
It worked properly before (a bit buggy) but now it doesn’t work.

this is my local script:

local function onInputBegan(input, gameProcessed)
	if gameProcessed then return end

	if input.UserInputType == Enum.UserInputType.Keyboard and input.KeyCode == Enum.KeyCode.T then	
		if player:DistanceFromCharacter(mouse.Target.Position) > 0 and player:DistanceFromCharacter(mouse.Target.Position) <= 7 then
			print(mouse.Target)
			if mouse.Target.Name == "WellPlacement"
				or mouse.Target.Name == "Union1" 
				or mouse.Target.Name == "Union2" 
				or mouse.Target.Name == "Union3" 
				or mouse.Target.Name == "Union4"
				or mouse.Target.Name == "TV_EnablerPart"
				or mouse.Target.Name == "VaultPart" 
				or mouse.Target.Name == "Lock"
				or mouse.Target.Name == "BedroomKeySlot"
				or mouse.Target.Name == "SinkWater" then
				
				local object = mouse.Target

				re2:FireServer(object.Name)
				
			elseif mouse.Target.Name == "Handle" then
				local object = mouse.Target.Parent
				
				re2:FireServer(object.Name)
			end
		end
	end
end
UserInputService.InputBegan:Connect(onInputBegan)

I dont know what is happening, there is nothing called “Part” there. Any help would be appreciate.

if then statement is too many…
Maybe entering it to folder and find from folder would be nice replacement, and can you print full name?

1 Like

make sure there isn’t any invisible parts Infront of the camera or the part ur trying to click, if there is and u can turn off CanCollide then do so and turn off CanQuery as your mouse will then ignore that part or use mouse.TargetFilter

1 Like

well, the problem is not if statement, it just mouse.Target cannot detect the “WellPlacement”, its just detect a thing called “Part”. I will check later.

well, i used targetFilter on the character model and i checked again, there is an invisible part. thank for your help!