Mouse..Target is nill

Im using a module script which is being required from a local script,

im trying to make a sword but mouse.Target is nil?

function Sword:Attack()
	print("1")
	local LocalPlayer = Players.LocalPlayer
	local Mouse = LocalPlayer:GetMouse()


	local ClosestPlayer = FindClosestPlayer()
	if ClosestPlayer then
		print("RAN 2 --------------------------")
		if LocalPlayer.Character.Humanoid.Health <= 0 then
		else
			print("RAN 2 --------------------------")
			print(Mouse.Target)
			if Mouse.Target then
				print("RAN 2 --------------------------")

i was debugging it with prints to see which part of my script wasn’t working

i was aiming on the player and it was printing nil

It says this on the documentation of Mouse.TargetFilter. You might have to stick to Raycasting instead.

Note that the Character of the Players.LocalPlayer is ignored by the mouse automatically.

3 Likes

Yeah, this. If what you’re saying is that you’re trying to click on your own player, Mouse.Target and other derivatives like Mouse.Hit ignore the player character. As suggested, you could use a raycast instead to draw a ray from the Camera’s position to Mouse.Hit and then return the raycast’s intercepted object.

1 Like

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