How would I select multiple parts?


This is my dragframe. I am trying to select all parts which are under the dragframe.

I’m not sure how to do this at all. Not asking for code, just an explanation; documentation and API.

I’m trying to do this in order to select several parts.
The issue is, googling it just shows results ‘how to make UI draggable’ which is not what I’m looking for. I’m looking for how to make a selection frame, so I can drag over certain parts and give them a selection box.

Example:

1 Like

Solution: Custom Selection Box/ Lasso Tool - #5 by blobbyblob

local pointBegin;
local pointEnd;

local function Search(Sources, a1, a2)
	--Regardless of whether we started in the top left, top right, etc., we want
	--a1 to be the top left corner and a2 to be the bottom right corner.
	a1, a2 = Vector2.new(math.min(a1.x, a2.x), math.min(a1.y, a2.y)), Vector2.new(math.max(a1.x, a2.x), math.max(a1.y, a2.y));

	local Found = {};

	local rel, x, y;
	for i, v in pairs(Sources) do

		--This does the same pointToObjectSpace logic as up above.
		rel = workspace.CurrentCamera.CFrame:PointToObjectSpace(v.Position);
		x, y = rel.x / -rel.z, rel.y / -rel.z;

		--Are we within bounds?
		if a1.x < x and x < a2.x and a1.y < y and y < a2.y and rel.z < 0 then
			table.insert(Found, v);
		end
	end
	return Found;
end

game.Players.LocalPlayer:GetMouse().Button1Up:Connect(function()
	local rel=workspace.CurrentCamera.CFrame:pointToObjectSpace(game.Players.LocalPlayer:GetMouse().Hit.Position)
	pointEnd=Vector2.new(rel.x/-rel.z, rel.y/-rel.z)
	local selectedParts = Search(
			workspace.Baseplate.Cities[game.Players.LocalPlayer:GetAttribute("Country")]:GetChildren(), pointBegin, pointEnd
		);
	warn(selectedParts)
end)
game.Players.LocalPlayer:GetMouse().Button1Down:Connect(function()
	local rel=workspace.CurrentCamera.CFrame:pointToObjectSpace(game.Players.LocalPlayer:GetMouse().Hit.Position)
	pointBegin=Vector2.new(rel.x/-rel.z, rel.y/-rel.z)
end)

Comments can be located on the original link.

4 Likes

If you want to select multiple parts, select the first, then hold ctrl the whole time while clicking the other two parts

1 Like

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