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