Here’s a download if anyone is interested:
SelectionBoxLassoTool.rbxl (58.4 KB)
Code:
local ContextActionService = game:GetService('ContextActionService')
local RunService = game:GetService('RunService')
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local SelBox = script.Parent
local hold = false
local x1,y1,x2,y2 = 0,0,0,0
local function comeUpWithAnameForThisFunction(actionName, inputState, inputObj)
if inputState == Enum.UserInputState.Begin then
hold = true
x1 = Mouse.X
y1 = Mouse.Y
elseif inputState == Enum.UserInputState.End then
hold = false
end
end
local function heartbeatConnection()
if hold == true then
SelBox.Visible = true
x2 = Mouse.X
y2 = Mouse.Y
SelBox.Size = UDim2.new(0,(x2 - x1), 0, (y2 - y1))
SelBox.Position = UDim2.new(0,x1,0,y1)
else
SelBox.Visible = false
end
end
local connection = RunService.Heartbeat:Connect(heartbeatConnection)
ContextActionService:BindAction("someNameImNotCreative", comeUpWithAnameForThisFunction, false, Enum.UserInputType.MouseButton1)
wait(10) -- simulating as if I got a bindable event or something
ContextActionService:UnbindAction("someNameImNotCreative")
connection:Disconnect()
SelBox.Visible = false
My Questions:
-
Can anything be simplified or be done more optimally?
-
I need a function that sees what parts are currently behind the Gui Frame. Where would the function go? It has to go inside of the heartbeatConnection(), since I want it to constantly update and for the user to see what parts are currently being highlighted, and whether to adjust the Gui Frame’s size or not. I already have a
selectPart(part)
function anddeselectPart(part)
function, so I just need to loop through them. How would I even get the parts? I don’t think I can send out thousands of raycasts, one per pixel…
Thanks!