Moves multiple parts instead of just one

I am making a plugin that requires moving when a key is pressed, but when I move something, and then stop it, then move another thing, it moves both of them. Here is my snippet of code. Variables and functions are not the problem.
There are no welds or constraints and are just plain parts.

if find(currentPressed, "Enum.KeyCode.M") and find(currentPressed, "Enum.KeyCode.X") then
			canmovey = false
			canmove = true
			canmovez = false
			for i,v in pairs(selected:Get()) do
				
				RunService.RenderStepped:Connect(function()
					if canmove == true then
							v.Position = Vector3.new(mouse.Hit.X, v.Position.Y, v.Position.Z)
				end
			end)
			end
			setPressed()
		end

Hey @aven_ue! It moves all parts because you have entered a looped function for i, v in pairs.

That function will get all the children of the object which has same properties resulting in all parts changing their position with respect to the workspace.

To avoid it. Name a specific part you want to move and type object:WaitForChild(“its name”).CFrame.
So its only a block it will work as you wish to move it.

It is getting all of the selected parts though and not a parts children.

1 Like

Yes to choose a specific part for a script it needs varibles.

local specificpart = “your part”
specificpart.CFrame = CFrame.new()

If you type i,v in pairs to chooses all the children of an object with same function and applies the function you entered to all of the parts.

I don’t think you are correctly understanding the Selection service. Selection | Documentation - Roblox Creator Hub

Oh! I checked it again.I have found that.

You did not apply the function select.So the script did not select one part, it selected all parts.

game.Selection:Get()[1]:SetPrimaryPartCFrame(CFrame.new())

I did get all the currently selected parts so I don’t think it has to do with that.

Found the issue! It was running multiple threads at a time.

1 Like

Ok. Finally you got it cool lol.