I have a script that I'm using coroutines in to get four NPCs to spawn at the same time. However, because I include this line in my code:
local activeNPCs = workspace.ActiveNPCs
local spawns = workspace.Spawns:GetChildren()
local function spawnNPC()
local NPCs = game:GetService("ReplicatedStorage").AvailableNPCs:GetChildren()
local randomNPC = NPCs[math.random(1,#NPCs)]
randomNPC.Parent = game:GetService("ReplicatedStorage").UnavailableNPCs
local newNPC = randomNPC:clone()
newNPC.Parent = activeNPCs
print(spawns[math.random(1, #spawns)])
newNPC:MoveTo(spawns[math.random(1,#spawns)].Position)
local newForceField = Instance.new("ForceField",newNPC)
game:GetService("Debris"):AddItem(newForceField, 10)
end
for _ = 1,4 do
spawnNPC()
wait()
end
I am unable to randomize spawning. So, how exactly does math.random work? I'm guessing that math.random is equal to a certain number at any given time, so when four functions are fired at the same time, the math.random value is the same. How can I randomize this?
