Hello! I am not too advanced at scripting, but I’m currently trying to make an area damage script. There is a tower, and when it attacks, I want it to damage multiple enemies in a range. The script I have summons the damage part, but it only damages one of the enemies, and not all of the enemies touching the part. Here is my script.
TL;DR: Area damage script isn’t working - No errors in the output.
local areaHitEnemies = {}
local function AreaDamage(tower, target)
local damagePart = Instance.new("Part")
damagePart.Size = Vector3.new(16,8,16)
damagePart.Color = Color3.new(1,0,0)
damagePart.Transparency = 0.3
damagePart.Anchored = true
damagePart.CanCollide = false
damagePart.CanQuery = false
damagePart.CFrame = target.HumanoidRootPart.CFrame
damagePart.Parent = workspace
damagePart.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Parent == game.Workspace.Enemies then
if not table.find(areaHitEnemies, hit.Parent.Name) then
table.insert(areaHitEnemies, hit.Parent.Name)
hit.Parent.Humanoid.Health -= tower.Config.Damage.Value
end
end
end)
task.wait(.1)
damagePart:Destroy()
areaHitEnemies = {}
end
I basically summon a relatively large part where the target is, and making it do damage to any enemy that touches it for a brief moment. I tried a debounce but that didn’t work, so this time I tried adding the enemy to a hit table, only damaging them if they aren’t already hit. There are currently no errors in the output, so I’m not sure what’s wrong.
(Forgot to say but yes, I do call the function)
If anyone could help, that would be amazing! Thank you!