I'm trying to take all the zombies off when the character dies and resets the level, but instead of spawning 3 zombies for level 1, it spawns an uncountable amount.
Zombie = game.Lighting.Zombie:Clone()
Num_Zom = 0
Level = 1
function Stance()
repeat local Zom2 = Zombie:Clone()
local pos = Vector3.new(math.random(-150,150),0,math.random(-150,150))
Zom2.Parent = workspace
Zom2:MakeJoints()
Zom2:MoveTo(pos)
Num_Zom = Num_Zom + 1
until Num_Zom == Level * 3
while wait(3) do
for i,v in pairs (game.Workspace:GetChildren()) do
if v.Name == "Zombie" and v.Humanoid.Health == 0 then
Num_Zom = Num_Zom - 1
v:remove()
end
if Num_Zom == 0 then
Level = Level + 1
for i,v in pairs (game.Players:GetPlayers()) do
v.stats.Level.Value = Level
end
Stance ()
end
end
end
end
game.Players.PlayerAdded:connect(function(Player)
Stance()
end)
game.Players.PlayerAdded:connect(function(Player)
local ting = false
Player.CharacterAdded:connect(function(Char)
if ting == true then
ting = false
Stance()
end
Char.Humanoid.Died:connect(function()
for i,v in pairs (game.Workspace:GetChildren()) do
if v.Name == "Zombie" then v:remove()
Level = 1
end
end
ting = true
end)
end)
end)
while wait(5) do print (Level) end
