Mouse.Target ignoring enemies

I am making a new entity system for a tower defense game I’m working and I have noticed that mouse.target is not returning any part in the enemy even if my mouse is over it

This is a big problem since the health gui is supposed to show when you put your mouse over the enemy

I think the problem is in the script which moves them but I’m not sure any help is appreciated

Btw this is a client script that moves them

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService =game:GetService("TweenService")
local PS = game:GetService("PhysicsService")
local Debris = game:GetService("Debris")
local RunService = game:GetService("RunService")

local Events =require(script.Parent.Parent:WaitForChild("Events"))
local Map = workspace:WaitForChild("Map")
local Waypoints = Map.Waypoints:GetChildren()

local NPCMover = {}
local Data = {}
local CFrames = {}
local Paths = {}

for index, waypoint in ipairs(Waypoints) do
	Paths[index] = {CFrame = waypoint.CFrame, Position = waypoint.Position}
end

Events.ClientListen("UpdateEnemy", function(data)	
	for index, d in ipairs(Data) do
		if d and d.Model and data[index] then
			d.Model.Config.Health.Value = data[index][2]
			if d.Model.Config.Health.Value <= 0 then
				d.Model:Destroy()
				table.remove(Data,index)
			end
		end
	end
end)

function NPCMover.GetDataAmount()
	return #Data
end

function NPCMover.AddEnemy(data)
	table.insert(Data, data)
end

local u6 = workspace:GetServerTimeNow()
local mode = Enum.BulkMoveMode.FireCFrameChanged
local accumulatorDelta = 0

RunService.Heartbeat:ConnectParallel(function()
	task.synchronize()
	local DeltaTime = (workspace:GetServerTimeNow() - u6)

	u6 = workspace:GetServerTimeNow()
	task.desynchronize()
	if #Data == 0 then
		return
	end

	local Parts = table.create(#Data)
	local Positions = table.create(#Data)

		for id, enemy in ipairs(Data) do
			local enemynode =enemy.Node
			local node = Paths[enemynode]
			local c = CFrame.new(node.CFrame.X, node.CFrame.Y, node.CFrame.Z)
			local speed = enemy.Speed
			local LastPos =enemy.LastPosition
			local Pos = Vector3.new(LastPos.X, LastPos.Y, LastPos.Z)
			local distance = (Pos - node.Position).Magnitude
			enemy.Moved += DeltaTime*speed/distance
			if enemy.Moved >= 1 then
				enemy.Moved = 0
				enemy.LastPosition = c
				enemy.Node += 1
			end
			local cframe = enemy.LastPosition:Lerp(c, enemy.Moved)
			Parts[id] = enemy.PrimaryPart
			Positions[id] = cframe
		end
	task.synchronize()
	workspace:BulkMoveTo(Parts, Positions, mode)
end)


return NPCMover

This is the script I used to print Mouse.Target

while task.wait(.1) do 
       print(game.Players.Lua_Moose:GetMouse().Target)
end

Yeah, already see the problem. You’re moving the NPCs with the client and getting what the mouse is hovering on the server’s side (it SEEMS like it, correct me if I’m wrong though). The Mouse.Target isn’t ignoring anything, it’s just the server doesn’t see everything that the client does. And as for your video demonstration, the server is seeing that the mouse is hovering over the part that you and the NPC’s are standing on.

Before you see how you should fix this, test it again and change the view from client to server side and see how the NPC’s aren’t moving. Again, it’s because you’re only moving the NPC’s on the client’s side. So, only the client is seeing them move. Not the server, OR ANY other player in fact, will see the exact same thing.

So, a simple fix would be just having the NPC’s move on a server script instead of a local script. I would say you should check what the player’s mouse is hovering over a local script for optimization purposes (if it does affect that, not too sure), but you don’t need to worry about that right now.

I’m printing the Mouse.Target on client according to output, and when I tried hovering over my character it didn’t show either in output

Well, I was referring to you seeing if the NPC’s were moving on the server’s side. I think it still is the fact that you’re moving the NPC’s on the client’s side, though.

And yeah, I did actually notice that you were printing it on the client’s side. (MY fault, my color contrast is difficult for me to see the different colors in the output right now).

I used a previous entity system that moved them on the client and it worked. I can show you the code for the previous one.

What if, instead, you just use game.Players.LocalPlayer? You could show me the code for the previous one, but I think it’s something to do with the target or targetfiltering of the mouse.