Moving a table of parts at once with handles

When I click on a part, it gets added into an dictionary like this, along with its highlight: boxes[part] = Instance.new("SelectionBox") (boxes being the dictionary)
Now, I need to be able to move the parts in my boxes dictionary, and all at the same time. Here’s my current code:

local GridSize = game:GetService("ReplicatedStorage"):WaitForChild("GridSize")

local PartToMove = workspace.Part
local movetool = PartToMove.Handles
local origin = PartToMove.CFrame
PartToMove.Handles.Parent = game:GetService("Players").LocalPlayer.PlayerGui

movetool.MouseDrag:Connect(function(a, b)
	if a.Value == 5 then
		PartToMove.CFrame = origin + PartToMove.CFrame.LookVector * math.round(b/GridSize.Value)*GridSize.Value
	elseif a.Value == 2 then
		PartToMove.CFrame = origin + PartToMove.CFrame.LookVector * -math.round(b/GridSize.Value)*GridSize.Value
	elseif a.Value == 1 then
		PartToMove.CFrame = origin + PartToMove.CFrame.UpVector * math.round(b/GridSize.Value)*GridSize.Value
	elseif a.Value == 4 then
		PartToMove.CFrame = origin + PartToMove.CFrame.UpVector * -math.round(b/GridSize.Value)*GridSize.Value
	elseif a.Value == 0 then
		PartToMove.CFrame = origin + PartToMove.CFrame.RightVector * math.round(b/GridSize.Value)*GridSize.Value
	elseif a.Value == 3 then
		PartToMove.CFrame = origin + PartToMove.CFrame.RightVector * -math.round(b/GridSize.Value)*GridSize.Value
	end
end)

movetool.MouseButton1Up:Connect(function()
	origin = PartToMove.CFrame
end)

I also have this:

local value = Vector3.new(0,0,0)
for i,v in boxes do
	value = value + i.Position
end
workspace.origin.Position = value/number -- number is just the length of the dictionary boxes

But how do I make it move all the parts at the same time? I really don’t want to iterate, there has to be a better solution. Also, I need it to be activated like an on/off switch by the key “2”. (where the arrows appear when 2 is pressed, but disappear and the parts are locked when 2 is pressed again)
Thanks!

Try looking into bulkmove. It’s a function under a world root (workspace)

I can’t really find much info or already made scripts for it that I can modify. May you help me out? Thanks!

Look at this??

I did, and I understood none of it :joy:

For example, how would it know to move which part to which position? I think I’d need to look at some examples of it working to grasp some kind of understanding, and then modify and bend it to my needs. Thanks!

1 Like

Heres an example of how you could use bulk move to based on your code above. I’m having trouble understanding what exactly your trying to achieve but I hope this helps you understand how bulk move to works.

local parts = {}
local cframes = {}

local boxes = {} -- Your dictionary of parts and selections

--Loop through boxes
for part, selection in pairs(boxes) do
	local cframe = part.CFrame -- This should where you want the part to move to
	
	table.insert(parts, part) --Bulk move to takes a table of parts and cframes
	table.insert(cframes, cframe) -- Insert both at same time so they share the same index in the array
end

-- Move all our parts
workspace:BulkMoveTo(parts, cframes, Enum.BulkMoveMode.FireCFrameChanged)

Also I would recommend getting good at understanding things from the roblox documentation as it can be a lot of help without having to ask other people all the time.

Yes, this helps!
Oooooh, share the same index in the array, that makes sense!
That cleared things up, thank you!
Okay, so basically, I have a table of parts
and I want to move them all (just for example) 1 stud in the positive X direction
With cframes, I’m afraid this can happen:


They all go their separate ways because they’re all oriented differently, and I can’t really orient them all the same way because some parts like cornerwedges have to have their specific orientation.

I’ll try to implement it though, gimme a sec (the video above is a failed attempt before I asked this question)

Here’s my current progress. I’ve done everything I could, but now I’m stuck.
HandlesBulkMoveTo.rbxl (52.1 KB)
I need a part.Position = partPositionBeforeMovment + distance, but I don’t know how to do it. Thanks!