Line 40, Workspace.Tower.towerShow.shootEnemies:40: attempt to index local 'target' (a nil value)
I'm not very good at 'for in pairs' functions. Having trouble connecting and securing a target block...
local Tower = script.Parent
local towerHolder = Tower.Parent
local shotAmmo = towerHolder.shotAmmo
local towerHealth = towerHolder.towerHealth
local damage = towerHolder.towerDamage
local Time = towerHolder.towerTimeShoot
local Enemies = game.Workspace.Bricks.Attackers
function Fire()
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
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
while wait() do
repeat
local target = v:FindFirstChildOfClass("Part")
until target.Active.Value == true --Problem...
break
end
end
end
end
print("Game Over")

1 comment
Didn't hit me that after "until" was outside of the loop. Thanks!