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