Line 43
Me again. Again, it's in a for in pairs... I want to get one target, I've tried FindFirstChild(OfClass) but it doesn't take it. How do I find a target?
local Tower = script.Parent
local towerHolder = Tower.Parent
local towerMain = towerHolder.towerMain
local shotAmmo = towerHolder.shotAmmo
local towerHealth = towerHolder.towerHealth
local damage = towerHolder.towerDamage
local Time = towerHolder.towerTimeShoot
local Enemies = game.Workspace.Bricks.Attackers
function Fire(attack)
local ammo = Instance.new("Part",shotAmmo)
ammo.Size = Vector3.new(.63,.63,.63)
ammo.BrickColor = BrickColor.new("Black")
ammo.CFrame = Tower.CFrame + Vector3.new(0,7.3,0)
ammo.CanCollide = false
ammo.Name = "Ammo"
ammo.TopSurface = "Smooth"
ammo.BottomSurface = "Smooth"
for i,v in pairs(Tower.AmmoParameters:GetChildren()) do
v.Parent.Damage.Value = damage.Value
v:Clone().Parent = ammo
--ammo.Follow.Disabled = true
end
ammo.Body.Position = attack.Position
game.Debris:AddItem(ammo,0.5)
end
while wait(1/Time.Value) do
if towerHealth.Value <= 0 then --Tower health has depleted, game over
break
end
local towerMag = towerHolder.towerMagnitude
for i,v in pairs(Enemies:GetChildren()) do
if v then -- if Enemies found then
local target
while wait() do
repeat wait()
target = v --Add something else to find only ONE target, not all children.
until target ~= nil and target.Alive.Value == true
local magnitude = (target.Position - towerMain.Position).magnitude
if magnitude <= towerMag.Value then
Fire(target)
end
break
end
end
end
end
print("Game Over")

1 comment
Although my "enemies" all have the same name. I realized and see many other techniques I can use thanks to you. Appreciate the help immensely!