This issue popped out of nowhere and has been driving me crazy. I have a script that spawns 100 NPCs around the map of my game. It has been working fine, but randomly (without changing the code whatsoever) it started spawning all the NPCs at the same position. I’ve tried many different ways of fixing it such as using Random.new() or math.randomseed(), but neither worked. Here is my script:
local dummy = workspace.NPCs:GetChildren()[1]
dummy.Parent = nil
function randomCF()
return CFrame.new(math.random(-304, 1742), 4, math.random(-1014, 995)) * CFrame.Angles(0, math.rad(math.random(0, 359)), 0)
end
function createDummy(name)
local new = dummy:Clone()
new.Name = name
new.HumanoidRootPart.CFrame = randomCF()
new.Parent = workspace.NPCs
return new
end
for i = 1, workspace:GetAttribute("NPCCount") do
createDummy("Player "..tostring(i))
end
You could try adding math.randomseed(tick()) at the top of your code or something. I think this is a problem that randomly happens and solves itself randomly.
Hey, I believe this issue is related to the fact that your are spawning them all at once - I believe random numbers are linked to the time they are generated.
Try this:
for i = 1, workspace:GetAttribute("NPCCount") do
createDummy("Player "..tostring(i))
wait(0.05)
end