hi, so im working on a zombie type game. Im trying to work on reducing lag and limiting the amount of zombies on screen. i have three values: zombiesAlive, zombiesRemaining, and zombiesOnScreen
zombiesAlive sets the number of how many zombies will be in a round, for example 6.
zombiesRemaining takes that value (6) pulls it into itself, so now it'll be set to 6 and will begin to decrees as zombies spawn, so that only the number given by zombiesAlive is all that spawns.
zombiesOnScreen gets added values by 1 each time a zombie is spawned in. i want to use this value as the indicator when to stop the loop/stop spawning
here's my script so far
local CS = game:getService("CollectionService")
while true do
wait(5)
for i, v in pairs(CS:GetTagged("spawner")) do
if game.ReplicatedStorage.Values.gameInProgress.Value == true then
if game.ReplicatedStorage.Values.zombiesRemaining.Value > 0 then
local NPC = game.ReplicatedStorage.Zombie:Clone()
NPC.Parent = v
NPC.HumanoidRootPart.CFrame = v.CFrame
CS:AddTag(NPC, "Zombie")
game.ReplicatedStorage.Values.zombiesRemaining.Value = game.ReplicatedStorage.Values.zombiesRemaining.Value - 1
game.ReplicatedStorage.Values.zombiesOnScreen.Value = game.ReplicatedStorage.Values.zombiesOnScreen.Value + 1
if game.ReplicatedStorage.Values.zombiesOnScreen.Value == 3 then
break
end
end
end
end
end
I only want 3 zombies on screen, i tried adding in a break to stop the loop
if game.ReplicatedStorage.Values.zombiesOnScreen.Value == 3 then
break
end
but zombies will still spawn in. what gives?

2 comments
Try printing before you break
i added print, it printed in output, but still did not break the loop :L