vq9o
(Metatable)
1
Code:
local module = {}
function module:init()
createNPC()
createNPC()
createNPC()
createNPC()
createNPC()
createNPC()
createNPC()
createNPC()
end
function createNPC()
pcall(function()
local npc = script.Storage.NPC:Clone()
local hairs = script.Storage.Hair:GetChildren()
local faces = script.Storage.Face:GetChildren()
local shirts = script.Storage.Shirt:GetChildren()
local pants = script.Storage.Pants:GetChildren()
local hair = math.random(1, #hairs)
local face = math.random(1, #faces)
local shirt = math.random(1, #shirts)
local pant = math.random(1, #pants)
hair:Clone()
face:Clone()
shirt:Clone()
pant:Clone()
shirt.Name = "Shirt"
pant.Name = "Pants
hair.Parent = npc
face.Parent = npc.Head
shirt.Parent = npc
pant.Parent = npc
npc.Parent = game.Workspace
local spawnLocation = script.Storage.Spawns:GetChildren()[math.random(#script.Storage.Spawns:GetChildren())]:Clone()
npc:SetPrimaryPartCFrame(spawnLocation.CFrame * CFrame.Angles(0,math.rad(math.random(360)),0) * CFrame.new(0,3,0))
end)
end
return module
Error:

I don’t know the problem with it.
Try this maybe:
local module = {}
function module:init()
createNPC()
createNPC()
createNPC()
createNPC()
createNPC()
createNPC()
createNPC()
createNPC()
end
function createNPC()
pcall(function()
local npc = script.Storage.NPC:Clone()
local hairs = script.Storage.Hair:GetChildren()
local faces = script.Storage.Face:GetChildren()
local shirts = script.Storage.Shirt:GetChildren()
local pants = script.Storage.Pants:GetChildren()
local hair = hairs[math.random(1, #hairs)]
local face = faces[math.random(1, #faces)]
local shirt = shirts[math.random(1, #shirts)]
local pant = pants[math.random(1, #pants)]
hair:Clone()
face:Clone()
shirt:Clone()
pant:Clone()
shirt.Name = "Shirt"
pant.Name = "Pants
hair.Parent = npc
face.Parent = npc.Head
shirt.Parent = npc
pant.Parent = npc
npc.Parent = game.Workspace
local spawnLocation = script.Storage.Spawns:GetChildren()[math.random(#script.Storage.Spawns:GetChildren())]:Clone()
npc:SetPrimaryPartCFrame(spawnLocation.CFrame * CFrame.Angles(0,math.rad(math.random(360)),0) * CFrame.new(0,3,0))
end)
end
return module
Wyzloc
(Wyzloc)
3
local module = {}
function module:init()
createNPC()
createNPC()
createNPC()
createNPC()
createNPC()
createNPC()
createNPC()
createNPC()
end
function createNPC()
pcall(function()
local npc = script.Storage.NPC:Clone()
local hairs = script.Storage.Hair:GetChildren()
local faces = script.Storage.Face:GetChildren()
local shirts = script.Storage.Shirt:GetChildren()
local pants = script.Storage.Pants:GetChildren()
local hair = hairs[math.random(1, #hairs)]
local face = faces[math.random(1, #faces)]
local shirt = shirts[math.random(1, #shirts)]
local pant = pants[math.random(1, #pants)]
hair:Clone()
face:Clone()
shirt:Clone()
pant:Clone()
shirt.Name = "Shirt"
pant.Name = "Pants"
hair.Parent = npc
face.Parent = npc.Head
shirt.Parent = npc
pant.Parent = npc
npc.Parent = game.Workspace
local spawnLocation = script.Storage.Spawns:GetChildren()[math.random(#script.Storage.Spawns:GetChildren())]:Clone()
npc:SetPrimaryPartCFrame(spawnLocation.CFrame * CFrame.Angles(0,math.rad(math.random(360)),0) * CFrame.new(0,3,0))
end)
end
return module
you made a typo
1 Like
vq9o
(Metatable)
4
It works but only 3 spawn. I don’t know the problem.