Still have questions? Join our Discord server and get real time help.
Log in to vote
0

# I'm trying to make zombies spawn. This is my code, but it won't work. Can I get help?

Asked by 2 months ago
local ZombieCount = game.ReplicatedStorage.GameInformation["ZombieCountMultiplier"].Value
local Zombie = game.Workspace["Zombie"]
Zombie.Parent = game.ReplicatedFirst

function PutIntoPlacer()
for Z = 100, ZombieCount do
local SpawnPointX = math.random(0, 100)
local SpawnPointZ = math.random(0, 100)
local ClonedZom = Zombie:Clone()

ClonedZom:MoveTo(Vector3.new(SpawnPointX, 100, SpawnPointZ))
ClonedZom.parent = game.Workspace

wait()

print(ClonedZom.HumanoidRootPart.Position)
end
print(ZombieCount.. " Zombies Placed")
end

wait(10)

PutIntoPlacer()


Thanks

### 2 answers

Log in to vote
0
Answered by
Isaque232 171
2 months ago

It may be because Z Is higher than ZombieCount Value which would prevent it from executing, since It's supposed to increase Z and execute the code everytime until it reaches the ZombieCount value, but since ZombieCount value is already below Z then it shouldn't execute the loop anymore.

In this case if you wanted to instead of increase Z, decrease it you can put ,-1 at the end.

for Z = 100, ZombieCount, -1 do


Which would decrease Z everytime instead of increasing it, for example, Z = 100 and ZombieCount = 90, it would execute the code until Z reaches 90.

so technically it would execute the code 10 times.

Hopefully this helps with your issue! Make sure to keep us updated if it didn't so we can get a properly solution for it!

If you want to know more about Loops, such as the For loop make sure to read Roblox Coding Basics -- Loops As It'll definitely help you with those kind of issues!

0
Thanks! My script works now. There were also a few other issues, but I fixed those. Darrend2 2 — 2mo
Log in to vote
0
Answered by
Miniller 331
2 months ago
Edited 2 months ago

Probably because you start the for loop with a big number, and maybe 100 is bigger than game.ReplicatedStorage.GameInformation.ZombieCountMultiplier.Value . I recommend to write 1, but I don't know what you want.