local rs = game:GetService('ReplicatedStorage') local entities = rs:WaitForChild('Entities') local zombie = entities.Zombies:WaitForChild('Zombie') local zombieFast = entities.Zombies:WaitForChild('Fast Zombie') local randomNumber = math.random(1,50) if randomNumber == 1 then local clone = zombie:Clone() clone.Parent = workspace:WaitForChild('Zombies') clone.HumanoidRootPart.CFrame = CFrame.new(math.random(-125, 125), 15, math.random(-125, 125)) elseif randomNumber == 2 then local cloneFast = zombieFast:Clone() cloneFast.Parent = workspace:WaitForChild('Zombies') cloneFast.HumanoidRootPart.CFrame = CFrame.new(math.random(-125, 125), 15, math.random(-125, 125)) end
So on and so forth what I'm saying is this will take a while to do for each individual zombie and I was just wondering if there was a way to make this shorter?
Try this and test if it works. I wasn't able to test so I can't guarantee that it works.
function SpawnZombie(ZombieType) local zombie = ZombieType:Clone() zombie.Parent = workspace:WaitForChild('Zombies') zombie.HumanoidRootPart.CFrame = CFrame.new(math.random(-125, 125), 15, math.random(-125, 125)) end local Zombie = "" local randomNumber = math.random(1,50) if randomNumber == 1 then Zombie = "zombie" SpawnZombie(Zombie) elseif randomNumber == 2 then Zombie = "zombieFast" SpawnZombie(Zombie) end
I made a quick idea for how to shorten this code, you can use a function that takes model and position parameters and returns the clone, making your code shorter.
local function CreateZombie(Zombie, RootCFrame) local Clone = Zombie:Clone() Clone:WaitForChild("HumanoidRootPart").CFrame = RootCFrame Clone.Parent = game.Workspace:WaitForChild("Zombies") return Clone end local RandomNumber = math.random(1,50) if RandomNumber == 1 then local clone = CreateZombie(zombie, CFrame.new(math.random(-125, 125), 15, math.random(-125, 125))) end
I hope you get the idea