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