Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

3 comments

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

0

add print checks print("got", mob.Name, "mobs left:", #workspace.Zombies.Mobs:GetChildren())

0

if nothing prints the script probably ran before zombies was added to the mobs folder

2 answers

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

3 comments

2

that won't work, the i,v is just to define the variables, it will have the same result he is currently having.

0

it works for me man.

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

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

This discussion is preserved as it was. New answers, comments, and votes are closed.