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
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
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
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.
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
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
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