How to make the cloned part position on the old part?

Basic BackGround: I am making a sytem that clone parts when ever specific number is randomly picked. And the part has to follow the player. But now the part is cloned in the same position as the old part and its not the thing i want. Here is the script

local player = game:GetService("Players")
local distance = 1
local number = 0
local function check  ()
	if part.Parent == workspace then
		for i,player in pairs(player:GetPlayers()) do
			local chr = player.Character
			if chr  then
				local humanoid = chr:WaitForChild("Humanoid")
				if humanoid then
					local torso = chr:WaitForChild("RightLowerLeg")
					local root = chr:WaitForChild("HumanoidRootPart")
					if root and torso then
						if (root.Position - part.Position).magnitude >= distance  then
							part.Position = torso.Position+Vector3.new(3,number,3)
							local region = Region3.new(torso.Position+Vector3.new(3,number,3))
							local stuffinregion = workspace:FindPartsInRegion3(region,nil,1)
							if stuffinregion.maxParts == 1 then
								number = number+1
								part.Position =torso.Position+Vector3.new(3,number,3)
								return number
							end
							part.CanCollide = false
							part.Anchored = true
			
						end
					end
				end
			end
		end
	end
	return number
end
while wait() do
	check()
end

1 Like

First of all, do you want the cloned part to be on the old position or not?

Because this sentence completely contradicts the title of this post, second of all, your script is realy messy.
Why are you using if statements to check if an instance exists if you’re already using :WaitForChild?
:WaitForChild will yield the script until the child is found, so the if statements are practically useless. You should change local chr = player.Character to local chr = player.Character or player.CharacterAdded:Wait(), you don’t need that many if statements.
Also, what is part? I don’t see anything that assigns part to anything.

Yea I know… how can I tidy up my script I am a really new beginner who have started scripting for like weeks only not even a month.

Well, first of all, you don’t need all those if statements if you’re already using :WaitForChild(), so you should remove those if statements, and you should change local chr = player.Character to local chr = player.Character or player.CharacterAdded:Wait(), this would yield the script until the player’s character is added to the game.

1 Like

Ok let me fix that first stuff first!