Trying to make a random spawn system where a random number gets assigned to a different spawn, then an npc spawns there. Only issue is that the random number only changes once. obivously thats an issue cause i want different spawns, not the same one every time.
CODE:
event.Zombies = function(zombAmount, duration)
local spawnFolder = game.Workspace:WaitForChild("zombieSpawns")
for i = 1, zombAmount, 1 do
print(i)
local zomb = models:WaitForChild("Zombie"):Clone()
local rSpawn = math.random(1, #spawnFolder:GetChildren())
print(rSpawn)
zomb:SetPrimaryPartCFrame(spawnFolder:FindFirstChild(rSpawn).CFrame)
zomb.Parent = game.Workspace.Zombies
end
task.spawn(function()
wait(duration)
for i, v in pairs(game.Workspace.Zombies:GetChildren()) do
if v.ClassName == "Model" and v.Name == "Zombie" then
v:Destroy()
end
end
end)
end
the print statement returns 36, the function gets called in a different script in serverscriptservice where every x amount of seconds it gets called since it’s like an event that’s supposed to happen in my game.
I should probably mention that the random number does change every time the code runs, but during the for loop when it’s supposed to change, it doesn’t