Hello Developers, How can I clone something multiple times? So I am making a like zombie monster game and it spawns zombies when the match starts. But I keep having to make a new :clone
part and this is wasting a lot of time in my case. Is there a way to make it clone multiple times? How can I do this? This will save a lot of time for me, so any help is appreciated.
You need to create values. The values will implement the zombie count for the game. Like in the script you should put this:
when Zombie.Parent = Workspace do
Zombie.Value = number —-Put the amount of zombies you want to spawn
That is a function with the zombie stuff. You should make sure that you need to create values for the zombies and localize them into the spawner. There should be multiple zombies spawning within the value that we created.
Oh ok I will try that out and see if it works!
Hmmm it puts a red line under when.
It shows a error in the output in when? Please provide the error statement so I can see what it says when you test it. Please provide the entire error sentence so I can review it.
I’m not sure this script works anymore but you can test it out if you’d like.
local NPC = game.ReplicatedStorage. --ObjectNameHere
local spawner = script.Parent
while true do
local Clone = NPC: Clone()
Clone.Parent = workspace
Clone.Torso.CFrame = spawner.CFrame
wait(3)
end
Here is what i want to do:
Normal.Parent = game.Workspace
local Normal2 = Monsters.Normal:clone()
Normal2.Parent = game.Workspace
Except instead of putting two of these I want to put 1 and make it clone it twice.
I want to control the amount of zombies getting cloned.
You could add a spawn cap; from my scripting knowledge I don’t know how to script something like that… hope I helped out though!
Oh ok its fine. I will use another way. Thanks for trying to help!
here is a quick way to do this!
local val = 1
while wait() do
local clonepart = game.Workspace.Part:Clone()
if clonepart.Parent == nil then
clonepart.Parent = game.Workspace
end
val = val + 1
if val == 15 then
break
end
end
To do this you have to add a val. I just added extra mesaures.
local NPCS = {}
local NPC = --path to npc
for i = 1, 10 do -- replace 10 with how many NPCs you want
local ClonedNpc = NPC:Clone()
table.insert(NPCS, #NPCS + 1, ClonedNpc)
end
for index, ClonedNPC in ipairs(NPCS) do
ClonedNPC.PrimaryPart.Position = Vector3.new() --origin
ClonedNPC.Parent = workspace
end
--do stuff
Oh ok. I will try this and see if it works.
Oh I could do this too. Ummm idk I will try both
Cinema’s method is more efficient. Use his instead of mine. Mine is just the basic solution.
Oh Ok I will use his. Thanks for the info
Thanks so much it works!
I will mark your answer a solution.