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

Why won't my cloning script work?

Asked by 9 years ago

I'm trying to have a part clone every second and move 10 units on the X Axis. Is there a way to clone something and have it move 10 units in a direction?

 while true do
wait(1)
f = script.Parent:Clone(game.Workspace)
r = script.Parent.Position.X
f.Position = (r - 10)
end
0
All 4 answers have different information, please look at all the answers so you understand your mistake and won't make the same one next time! EzraNehemiah_TF2 3552 — 9y

4 answers

Log in to vote
0
Answered by 9 years ago
--f is the original part
--c is the new cloned part
while true do
wait(1)
f = script.Parent
fpos =  f.Position
c = f:Clone()
c.Parent = game.Workspace
c.Position = Vector3.new(fpos.X - 10, fpos.Y, fpos.Z)
end

If this doesn't work, let me know and I'll try to fix the script. If it does work, let me know! Good luck on your scripting journey!

0
Just letting you know, but you forgot a '.' between c and Position. This script should work besides that. dyler3 1510 — 9y
0
This script clones it but it doesnt move the position. attackonkyojin 135 — 9y
0
@ dyer Thanks for letting me know! @attack The script should work now! iUnEarthly 85 — 9y
Ad
Log in to vote
1
Answered by
dyler3 1510 Moderation Voter
9 years ago

You had a few mistakes in your script. Anyways, here's the fixed one, and I'll explain your mistakes after the script:

while true do
    wait(1)
    f = script.Parent:Clone()
    f.Parent = game.Workspace
    r = script.Parent.Position
    f.CFrame = CFrame.new(r)*CFrame.new(-10,0,0)
end

So, in your script you had this:

f.Position = (r - 10)

This in incorrect because the game needs you to specify what type of data you're using. Here, I fixed it, and put "CFrame.new" before to specify it. "CFrame" is the same as "Vector3" which specifies location, but "CFrame" can be used more flexibly, which is why I decided to switch to that.


f = script.Parent:Clone(game.Workspace)

Your other error was when you put the parent of the cloned part inside the cloning methods parentheses. This doesn't work for whatever reason, so you would need to set the parent outside of that.


Anyways, I really hope I helped clarify some things for you. Good luck scripting, and I hope I helped :P

0
Um dude, there was nothing wrong with f.Position = Vector3.new(r - 10). You are allowed to leave it like that. EzraNehemiah_TF2 3552 — 9y
Log in to vote
0
Answered by 9 years ago

I don't think you can put the location you want to clone the object to into the clone method, unfortunately, I fixed it below for you by adding the extra line which will parent f into workspace. Also, make it a valid position with CFraming

 while true do
wait(1)
f = script.Parent:Clone() --Can't put clone parent here
f.Parent = game.Workspace -- Added parent line here
r = script.Parent.Position.X
f.CFrame = CFrame.new(r)*CFrame.new(-10,0,0) -- CFraming
end

0
You would also need to fix the Positioning of it. He didn't put the "Vector3" there. dyler3 1510 — 9y
0
o yea, ill fix that right now dragonkeeper467 453 — 9y
Log in to vote
0
Answered by 9 years ago

For cloning, there are no parameters. So there is no script.Parent:Clone(game.Workspace). Also, if you leave only one number(in this case it's the part's X axis - 10), only the X axis will be set and the rest of the values like y and z will be 0 on default.


Clone

To set the parent of a cloned part, just set the parent like how you usually do:

f = script.Parent:Clone()
f.Parent = workspace --Or game.Workspace
--or
script.Parent:Clone().Parent = workspace --Or game.Workspace

Positions

Use CFrame instead incase there is a part in the way. Use Vector3.new or CFrame.new. You just can't have random numbers everywhere.

f.Position = Vector3.new(r - 10) --only changes the X

If you want to change the other values add the Y and Z values

f.Position = Vector3.new(r - 10, 0, 50)

If you want to change it RELATIVE to the original part's position:

f.Position = (f.Position.X,f.Position.Y+10,f.Position.Z ) --Moves the part up 10 studs.


Final Product

while wait(1) do
    local p = script.Parent:Clone()
    p.Parent = workspace
    local pos = p.Position
    p.CFrame = CFrame.new(p.X-10,p.Y,p.Z)
end



Hope it helps!

Answer this question