Ok so im working on a small side project tds type game, and i ran into a small bug.
The tower wont kill the mob.
the script:
local tower = script.Parent
local mobs = workspace.Mobs
local function FindNeartestTarget()
local maxDistance = 50
local nearestTarget = nil
for i, target in ipairs(mobs:GetChildren()) do
local distance = (target.HumanoidRootPart - tower.Position).Magnitude
print(target.Name, distance)
if distance < maxDistance then
print(target.Name, "is nearest target found so far")
nearestTarget = target
maxDistance = distance
end
end
return nearestTarget
end
while true do
local target = FindNeartestTarget()
if target then
target.Humanoid:TakeDamage(25)
task.wait(1)
end
end