So i when this script runs it copies the zombie from replicatedstorage to workspace but it doesnt do the math. (zombieamount = zombieamount - 1)

It does it every once and a while not every time but it does the zombie copy.

THE ERROR HAS NOTHING TO DO WITH MATH.RANDOM

zombieamount = 5
function spawned()
zombieamount = zombieamount - 1
end

local zombiespawner1 = coroutine.wrap(function()
while wait(10) do
print'go'
if endnow == false then
if zombieamount >= 1 then --barrier 1
local rand1=math.random(1,2)
if rand1 == 1 then
if script.Barrier1.Value == true then
spawned()
zombie = game.ReplicatedStorage.Zombie:Clone()
zombie.Parent = game.Workspace.ZombieSpace
end
end
end
end
end
end)