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

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

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

✓ Accepted answer

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!

1 comment

0

Thanks! My script works now. There were also a few other issues, but I fixed those.

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.

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