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

How do I count the amount of something in Workspace?

Asked by
SuperFryX 130
8 years ago

I am making a zombie kind of game and I want to be able to detect how many Zombies are in the workspace so I can make it stop spawning them when the amount of zombies is too high. How would I count them?

0
I'm confused as to why this got downvoted? SuperFryX 130 — 8y

1 answer

Log in to vote
2
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
8 years ago

If they are all called "Zombie" then you can count the number of objects in workspace that are called "Zombie"

local zombies=0
for _,v in pairs(workspace:GetChildren())do
    if v.Name=="Zombie"then
        zombies=zombies+1
    end
end

Something better you could do is just have a folder in workspace where you store all of the zombies. Then you can just check #zombiefolder:GetChildren()

Ad

Answer this question