Is there a way to find what parts a gui object is colliding with?

So Im trying to make a gui similar to the windows selection tool, one problem is that I can’t figure out a way to see what parts are overlapping or touching the gui. Here is my code:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local userinputservice = game:GetService(“UserInputService”)
local hold = false
local runservice = game:GetService(“RunService”)
local pastposition
local pastx
local pasty


player.CameraMaxZoomDistance = 50

userinputservice.InputBegan:connect(function(key,chat)
if chat == false and key.UserInputType == Enum.UserInputType.MouseButton1 then
pastposition = UDim2.new(0,mouse.X,0,mouse.Y)
script.Parent.Position = pastposition
pastx = mouse.X
pasty = mouse.Y
hold = true
end
end)

userinputservice.InputEnded:connect(function(key)
if key.UserInputType == Enum.UserInputType.MouseButton1 then
hold = false
end
end)

runservice.RenderStepped:connect(function()
if hold == true then
script.Parent.Visible = true
local newsize = UDim2.new(0,mouse.X+2,0,mouse.Y+2) - pastposition
script.Parent.Size = newsize
local children = workspace:GetChildren()
elseif hold == false then
script.Parent.Visible = false
end
end)

https://gyazo.com/3f89f43e5d59074a1865fe74afec3bde

You can mark the position of the mouse in 3d space when you click, mark it again when you release, and then use Region3 to get all parts in that area.

Cheers.

4 Likes

Thanks a lot, just if anyone that had the same problem as me, here is what I ended up with:
function select()
local region
local greatest
local least
if mouse.Hit.p.X > pastmouse.p.X then
greatest = mouse.Hit.p
least = pastmouse.p
elseif pastmouse.p.X > mouse.Hit.p.X then
greatest = pastmouse.p
least = mouse.Hit.p
end
print(greatest)
print(least)
region = Region3.new(least - Vector3.new(0,10,20),greatest + Vector3.new(0,10,20))
local parts = workspace:FindPartsInRegion3(region,nil,math.huge)
print(unpack(parts))
end

1 Like