Clone not working

so all I simply want is the block to clone but it doesn’t work for some odd reason.

So I’ve tried lots of solutions but in the end, it was all just the Clone command not working.

The issue is the block does not clone when it still exists and when the code has no errors. This is my code:

wait(math.random(3,8)) -- Nothing to do with the clone
script.Parent:Clone()
script.Parent.Anchored = false -- Not for the clone
script.Parent.CanCollide = true -- Not for the clone
5 Likes

You need to put the clone into a variable so you can reference it and change its properties. After you’re done with that, insert it into the game

local clone = script.Parent:Clone()
clone.Anchored = false
clone.CanCollide = true
clone.Parent = game.Workspace --you can replace game.Workspace with whatever you intend to parent the clone to
3 Likes

well the other code is for the other block that was in before the clone its complicating but it makes sense if you know what I mean

wait(math.random(3,8)) -- Nothing to do with the clone
script.Parent:Clone()
script.Parent.Anchored = false -- Not for the clone
script.Parent.CanCollide = true -- Not for the clone

You can immediately clone the block and then parent it, and then after that you can change the properties of the original block.

script.Parent:Clone().Parent = game.Workspace
script.Parent.Anchored - false
script.Parent.CanCollide = true

oh erm they are already in workspace its just the anchored part and the can collide part is so it can fall and so it wont fall through the map.

Have you disabled your script?

Is the archivable property on the part set to false? If yes, set it to true. If you disable the archivable property on a part, it won’t clone.

Try putting it in a variable:
local clone = script.Parent:Clone()
like @downcrusher69 said. Then print the .Name of the cloned part. If you do this then you’ll see if it is cloning or not. It’s more just debugging than anything but you could try it and see if it prints the name or if you error.

First, take the original one in a variable, then clone it, and then go from there.
Example:

local original = script.Parent
local cl0ne = script.Parent:Clone()

original.Anchored = false
original.CanCollide = true

Just to clarify what others eg. @downcrusher69 are saying, as I think what the OP is not understanding
is that when you Clone(), the .Parent of the clone is set to nil (so the clone does not
end up with the same parent as the original: You must parent the clone.) eg.

wait(math.random(3,8)) -- Nothing to do with the clone
script.Parent:Clone().Parent = script.Parent.Parent  -- Notice here
script.Parent.Anchored = false -- Not for the clone
script.Parent.CanCollide = true -- Not for the clone
2 Likes

If you put the script in the brick it will clone even more causing your game to possible experience lag, its like a virus.

Put in a script or localscript in the workspace and just clone it like normal,

workspace.Part:Clone()
1 Like

The code has no errors because it doesn’t know what you’re trying to do,
when you call Instance:Clone(), a cloned object is created but its parent property is nil, so you can’t see the clone.

Store the cloned object in a variable

 local clone = script.Parent:Clone()
 clone.Anchored = false -- change properties before parenting
 clone.Parent = workspace -- anything you need it parented too
 -- or
 script.Parent:Clone().Parent = workspace

@Sayfside why do you need to clone scripts? You can achieve a similar effect by just cloning parts how many times you want through some loop,

  local part = script.Parent
  for count = 1, 10 do -- clones 10 times
      local clone = part:Clone()
      local m = math.random(3,8)
      clone.Position = clone.Position + Vector3.new(m, 0,m) 
      clone.Parent = workspace
  end
1 Like

THIS.

@OP:

When you clone something, it clones all its children (including your script). So your script will run for the new part, which clones another part that has the same script, so the script runs again and clones the cloned part, and it keeps going on and on and on…

This isn’t to do with why it’s not cloning - like others have mentioned, if the parent is nil and you don’t have a reference to the object, it doesn’t really exist (unless it’s some ghost in memory).

Roblox has some built-in safeties to stop this infinite cloning but it’s best not to rely on them. I believe it limits at 3 clones until it internally stops the script from running. Don’t run a clone script from the child

i.e., put the script anywhere EXCEPT inside the part

3 Likes

Didnt know that his part was somewhere else then workspace.

1 Like

Okay so I was sleeping cuz I was tired but I will try your solutions :smiley:

Thanks it worked exactly as I intended it to work.