Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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

Log in to vote
0
Answered by 6 years ago
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.

0
Didn't work. ShadowNinja1080 6 — 6y
0
Oh I had forgot to mention, make sure to put that code into a LocalScript inside StarterPlayer > StarterPlayerScripts. Sorry, my bad! isaacsoccer 45 — 6y
Ad

Answer this question