while task.wait(0.001) do
if script.Parent.Triggered.Value == true then
local high = 0
local low = 999999999999
local enemy = script.Sort
local enemies = workspace.Enemies
local waitTime = 0.01 -- time to wait, in seconds
-- create a new task
for i, v in pairs(enemies:GetChildren()) do
local distance = (v.Torso.Position - script.Parent.OriginalBall.Value.Position).Magnitude
if distance < 12 then
v.Zombie =- 35
print(v.Zombie.Name)
script.Parent.ExplosionEffect.Enabled = true
script.Parent.Transparency = 1
end
script.Parent.ExplosionEffect.Enabled = true
script.Parent.explode:Play()
print('explosionradius')
task.wait(1)
script.Parent.ExplosionEffect.Enabled = false
script.Disabled = true
task.wait(0.05)
script.Parent:Destroy()
end
end
end
What’s in the OriginalBall.Value ? If it’s an object then it’s probably being declared from the client and checked on the server. You should declare it from the server.
I am guessing it probably works once and then stops at the second iteration. The issue is that you are destroying “script.Parent” in your last line, yet when it iterates in the for loop again, on the “distance” variable, it is trying to call “script.Parent” again, except script.Parent is now nil because it has been destroyed in the previous iteration.
I am not sure what you are precisely trying to do, but what you could do to try fixing it is take this bit of your code
task.wait(0.05)
script.Parent:Destroy()
and move it right before the last “end” (basically right after the for loop). Try to see what it does when you do that.