My spawner is spawning only 1 zombie instead of looping it
Here is the script:
local spawner = script.Parent
while true do
local zombie = game.ReplicatedStorage.NPCs:FindFirstChild("Zombie [Enemy]"):Clone()
zombie.Parent = game.Workspace
zombie.HumanoidRootPart.CFrame = spawner.CFrame + Vector3.new(0,2,0)
wait(5)
end
You might not be waiting long enough, because it adds a zombie before waiting 5 seconds, and you’re adding a Vector3 onto a CFrame which you cant do under normal conditions, add a CFrame onto it instead.
I’ve waited enough and still spawning only 1 zombie, and if I change to wait 1 second, it spawn 2 zombies and I’ve changed the CFrame to: zombie.HumanoidRootPart.CFrame = CFrame.new(spawner.Position + Vector3.new(0,2,0))
Not sure if or why this would make a difference, but might as well give it a try. Try utilizing ServerStorage rather than ReplicatedStorage. Let me know if the results are different.
Nice! I was midway typing this while I saw this so im still going to post it.
It may be you using “while true do” what you could do is the following:
local spawner = script.Parent
while task.wait(5) do
local zombie = game.ReplicatedStorage.NPCs:FindFirstChild("Zombie [Enemy]"):Clone()
zombie.Parent = game.Workspace
zombie.HumanoidRootPart.CFrame = spawner.CFrame + Vector3.new(0,2,0)
end
This Runs the script every 5 seconds and also cuts the script down by 1 line.
I also read somewhere (Im not sure if this is true or not) that it is generaly bad practice to use “While true do” and insted use “White task.wait() do” btw.