The tower wont attack the other enemy instead when it kills 1 enemy an error will pop up - Humanoid is not a valid member of Model "Zombie"
local function Splash(targeted, obj)
targeted.Humanoid:TakeDamage(obj.Config:WaitForChild("Damage").Value)
local radius = obj.Config.SplashRadius.Value
local Ymargin = 3 -- this is how high or below your target can be from the splash. Make it higher to make it more lenient.
local Enemies = workspace.Mobs:GetChildren()
local targets = {}
for i, target in pairs(Enemies) do
local vectordistance = (targeted:WaitForChild("HumanoidRootPart").Position - target:WaitForChild("HumanoidRootPart").Position) -- this is a vector
local distance = vectordistance.Magnitude -- this is a number
local Ydistance = math.abs(vectordistance.Y) -- number that displays how far they are from each other on the Y-axis
if distance <= radius and Ydistance < Ymargin and target ~= targeted then
table.insert(targets, target)
targeted.Humanoid:TakeDamage(obj.Config:WaitForChild("Damage").Value)
end
end
end
for i, target in pairs(Enemies) do
local targetHumanoidRootPart = target:FindFirstChild("HumanoidRootPart")
local targetHumanoid = target:FindFirstChild("Humanoid")
if targetHumanoidRootPart and targetHumanoid then
local vectordistance = (targeted.HumanoidRootPart.Position - targetHumanoidRootPart.Position) -- this is a vector
local distance = vectordistance.Magnitude -- this is a number
local Ydistance = math.abs(vectordistance.Y) -- number that displays how far they are from each other on the Y-axis
if distance <= radius and Ydistance < Ymargin and target ~= targeted then
table.insert(targets, target)
targetHumanoid:TakeDamage(obj.Config:WaitForChild("Damage").Value)
end
end
end
It will check if humanoid rootpart and humanoid exists and then access it.
Let me know if it helps.
local targetedHumanoid = targeted:FindFirstChild("Humanoid")
if targetedHumanoid then
targetedHumanoid:TakeDamage(obj.Config:WaitForChild("Damage").Value)
else
warn("No Humanoid found in targeted model:", targeted.Name)
end