Clone() Always clonning to same position [HELP]

I have coded something like that (deleted some parts for being clear). I want to make clone a part when player clicked to image button. It just works, it clone 3 parts on origininal with +2 Y position. But it always clone to same position. I want to make them clone always adding +2. Like first clicked added 3 parts to original part +2y +4y +6y and after that when clicked again it should be +8y +10y +12y… but it just stucked on same positions… I hope someone understand that and help me. Thank you.

local originalpart = workspace.Holders.Part
local copy = originalpart:Clone()
local copy2 = originalpart:Clone()
local copy3 = originalpart:Clone()

for i, Button in pairs(script.Parent.AnswerGui.Frame:GetChildren()) do
	if not Button:IsA("ImageButton") then continue end
	Button.MouseButton1Click:Connect(function()
			
		local answersimg = Button.Image
		if string.find(answersimg:lower(), script.Parent.Answer.Value) then
		
			copy.Parent = originalpart.Parent
				copy2.Parent = originalpart.Parent
				    copy3.Parent = originalpart.Parent
			copy.CFrame = CFrame.new(originalpart.CFrame.X,originalpart.CFrame.Y+2,originalpart.CFrame.z)
	task.wait(0.25)
				copy2.CFrame = CFrame.new(originalpart.CFrame.X,originalpart.CFrame.Y+4,originalpart.CFrame.z)
	task.wait(0.25)
				copy3.CFrame = CFrame.new(originalpart.CFrame.X,originalpart.CFrame.Y+6,originalpart.CFrame.z)
		else
			--
		end
	end)
end

You should add a Vector3 to the CFrame instead.

copyX.CFrame += Vector3.new(0, x, 0)

I hope this helps!

1 Like

Cool but, it deletes old ones, not clonning new parts on old clones.

Here you go.

local originalpart = workspace.Holders.Part

for i, Button in pairs(script.Parent.AnswerGui.Frame:GetChildren()) do
	if not Button:IsA("ImageButton") then continue end
	Button.MouseButton1Click:Connect(function()
			
		local answersimg = Button.Image
		if string.find(answersimg:lower(), script.Parent.Answer.Value) then
		    local copy = originalpart:Clone()
            local copy2 = originalpart:Clone()
            local copy3 = originalpart:Clone()
			copy.Parent = originalpart.Parent
				copy2.Parent = originalpart.Parent
				    copy3.Parent = originalpart.Parent
			copy.CFrame = CFrame.new(originalpart.CFrame.X,originalpart.CFrame.Y+2,originalpart.CFrame.z)
	task.wait(0.25)
				copy2.CFrame = CFrame.new(originalpart.CFrame.X,originalpart.CFrame.Y+4,originalpart.CFrame.z)
	task.wait(0.25)
				copy3.CFrame = CFrame.new(originalpart.CFrame.X,originalpart.CFrame.Y+6,originalpart.CFrame.z)
                originalpart = copy
		else
			--
		end
	end)
end

You’re only adding, there’s no check to change the position values on another click. By doing this, it’ll repetitively stack if you click the button.

1 Like

Can you please elaborate? In the mean time, this is what I intend to modify on your code:

copy.CFrame += Vector3.new(0, 2, 0)
task.wait(0.25)
copy2.CFrame += Vector3.new(0, 4, 0)
task.wait(0.25)
copy3.CFrame += Vector3.new(0, 6, 0)
1 Like

Thanks, it working but it just add +2y instead of +6y in total after second click.

Change originalpart = copy to originalpart = copy3 and see how that works out

1 Like

I know, i just made it like you said but it just after second click changed positions of clonned parts. Not clonned second time and added on clones

Thank you and @Mastercheterpoop to help! it worked.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.