Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make a script whereby all the zombies in the folder with the same name are destroyed?

Asked by 5 years ago
Edited 5 years ago

I get no errors when executing this script can someone tell me what I'm doing wrong and fix it for me? Please and thank you.

for _, mob in pairs(workspace.Zombies.Mobs:GetChildren()) do
    if mob.Name == "Zombie" then
        mob:Destroy()
    end
end

https://imgur.com/a/CTEQSk7

1
I tried this and it seems to work, do you have an image of when it's not working? Possibly try adding a wait() after the first end SerpentineKing 3885 — 5y
0
add print checks print("got", mob.Name, "mobs left:", #workspace.Zombies.Mobs:GetChildren()) hellmatic 1523 — 5y
0
if nothing prints the script probably ran before zombies was added to the mobs folder hellmatic 1523 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Try using i, v in pairs instead of _, mob in pairs:

for i, v in pairs(workspace.Zombies.Mobs:GetChildren()) do
    if v.Name == "Zombie" then
        v:Destroy()
    end
end
2
that won't work, the i,v is just to define the variables, it will have the same result he is currently having. SerpentineKing 3885 — 5y
0
it works for me man. CaptainD_veloper 290 — 5y
1
I know the function works when we test it, but obviously its not working for the asker, since this is exactly the same function they put into their question, but with different variable names SerpentineKing 3885 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Before running the for loop, add a wait() so that the zombies can spawn into the folder:

wait(5) -- Waits 5 seconds before the loop starts. During this time, everything has time to spawn in.
for _, mob in pairs(workspace.Zombies.Mobs:GetChildren()) do
    if mob.Name == "Zombie" then
        mob:Destroy()
    end
end

Answer this question