Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make mouse select multiple parts at the same time?

I want to make it so when you like hold the left click button on your mouse, it would create a square that would select multiple parts, depending on the range of how big you made the square while holding left mouse button. How do I do it? What things do I need.

function onClicked()
    
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

1 answer

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local selectedparts = {}
--[[
	This is an array, I made it so that you
	can store the selected parts and
	modify them.
--]]

mouse.Button1Down:connect(function()
	if mouse.Target ~= nil then
		local object = mouse.Target
		local selectionbox = Instance.new("SelectionBox", object)
		selectionbox.Adornee = object
		table.insert(selectedparts, object)
	end
end)

local function cleararray() --Call this function to clear the selected parts cleararray()
	for i,v in pairs(selectedparts) do
		if v:FindFirstChild("SelectionBox") then
			v:Destroy()
		end
	end
	selectedparts = {}
end

This script will select the parts you click on. I'm not sure how to make a script where you can click and drag to select. But I assume it would have something to do with Region3's. But either way, I hope this can help you.

2 comments

0

Didn't work.

0

Oh I had forgot to mention, make sure to put that code into a LocalScript inside StarterPlayer > StarterPlayerScripts. Sorry, my bad!

This discussion is preserved as it was. New answers, comments, and votes are closed.