So I'm making a spawner that spawns different types of zombies, and I've got the random zombies and spawning down, but I need to know how to change the wait time every time it loops.
Here's my script:
local zombieChoice = math.random(1, 5)
while true do
math.randomseed(tick())
wait(math.random(1, 5))
if zombieChoice == 1 then
zombieChoice = math.random(1, 5)
local zombie = game.Lighting.Zombie1:clone()
zombie.Parent = game.Workspace.Zombies
zombie:MoveTo(script.Parent.Position)
zombie:MakeJoints()
elseif zombieChoice == 2 then
zombieChoice = math.random(1, 5)
local zombie = game.Lighting.Zombie2:clone()
zombie.Parent = game.Workspace.Zombies
zombie:MoveTo(script.Parent.Position)
zombie:MakeJoints()
elseif zombieChoice == 3 then
zombieChoice = math.random(1, 5)
local zombie = game.Lighting.Zombie3:clone()
zombie.Parent = game.Workspace.Zombies
zombie:MoveTo(script.Parent.Position)
zombie:MakeJoints()
elseif zombieChoice == 4 then
zombieChoice = math.random(1, 5)
local zombie = game.Lighting.HallowZombie1:clone()
zombie.Parent = game.Workspace.Zombies
zombie:MoveTo(script.Parent.Position)
zombie:MakeJoints()
elseif zombieChoice == 5 then
zombieChoice = math.random(1, 5)
local zombie = game.Lighting.HallowZombie2:clone()
zombie.Parent = game.Workspace.Zombies
zombie:MoveTo(script.Parent.Position)
zombie:MakeJoints()
end
end
You don't really need to care about the part that spawns the zombies. The part I'm having trouble with is the wait time between spawning.
This does choose a random spawn time, but only once. It chooses a random time, then sticks to that time. So sometimes it's spitting out a zombie a second and other times it's waiting a while, but either way, it's staying on the same wait time and not changing it every time a zombie spawns. I've tried using a variable that changes every time the zombie spawns, but that ends up with the same result. How would I make it so the wait time changes every time the loop repeats? Thanks!

1 comment
I don't see anything wrong.