Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Clone script wont duplicate model?

Asked by 6 years ago

Everything works, but it never duplicates. Nothing comes up in output.

wait(2)
script.Parent.Parent.Parent.Enabled=true
workspace.burger.Handle.Anchored=true

function onClick()
    workspace.burger:Clone()
    wait(.1)
    workspace.burger.Handle.Position= Vector3.new(301.87, 7.692, 485.56)
    workspace.burger.Handle.Anchored=false
end

script.Parent.MouseButton1Down:connect(onClick)
0
The clone requires a parent, which you never give it. "workspace.burger:Clone().Parent = workspace" Ultimate_Piccolo 201 — 6y

3 answers

Log in to vote
0
Answered by 6 years ago

Your current script seems a bit messy, let's switch things up to make it look better:

wait(2)
script.Parent.Parent.Parent.Enabled = true
local B = game.workspace:WaitForChild('burger').Handle

B.Anchored = true

script.Parent.MouseButton1Down:Connect(function()
    local CB = B:Clone()
    wait(0.1)
    CB.Position = Vector3.new(301.87, 7.692, 485.56)
    CB.Anchored = false
    CB.CanCollide = true -- make sure it doesn't fall through the world
end)

Now this is much better, assuming this is a local script, it's not good to access parts with a local script. This won't work if you have FE enabled. Now, the thing about your script is if nothing comes up in the output, you have to find where the code stops. So, you add prints.

wait(2)
script.Parent.Parent.Parent.Enabled = true
local B = game.workspace:WaitForChild('burger').Handle

B.Anchored = true
print('1')
script.Parent.MouseButton1Down:Connect(function()
    local CB = B:Clone()
    wait(0.1)
    print('2')
    CB.Position = Vector3.new(301.87, 7.692, 485.56)
    CB.Anchored = false
    CB.CanCollide = true -- make sure it doesn't fall through the world
    print('3')
end)

If all 3 prints, everything ran, meaning that it works. If it doesn't find out what you are doing wrong. Now, I have copied your script, meaning that this was based on your idea. I have helped you make your code better so that it will run smoother. If it doesn't work and doesn't print a part, find the error and post on this post and I will get back to you.

Good luck, I can only help you so far if there is no errors. Wish you luck!

Ad
Log in to vote
-1
Answered by
Meqolo 78
6 years ago

Its not anchored, it will just fall.

Log in to vote
-1
Answered by 6 years ago
Edited 6 years ago

When using :Clone() it must be done within defining a variable like so:

wait(2)
script.Parent.Parent.Parent.Enabled=true

workspace.burger.Handle.Anchored=true

function onClick()
    burger = workspace.burger:Clone()
    wait(.1)
    burger.Handle.Position= Vector3.new(301.87, 7.692, 485.56)
    burger.Handle.Anchored=false
end

script.Parent.MouseButton1Down:connect(onClick)

The reason it is like this is so that the script knows that whenever the object is moved around, an original copy of the object must still be in it's place.

Answer this question