local oldX = mouse.X
local oldY = mouse.Y
frame.Position = UDim2.new(0, oldX, 0, oldY)
while state == true do
heartbeat:Wait()
frame.Size = UDim2.new(0, mouse.X - oldX, 0, mouse.Y - oldY)
local topLeft = frame.AbsolutePosition
local bottomRight = topLeft + frame.AbsoluteSize
print(topLeft)
print(frame.Position)
print(bottomRight)
for i = 1, #selectable do
local vector = camera:WorldToScreenPoint(selectable[i].Position)
print(vector.X, vector.Y)
if (topLeft.X < vector.X and vector.X < bottomRight.X) and (topLeft.Y < vector.Y and vector.Y < bottomRight.Y) then
selectable[i].SelectionBox.Visible = true
end
end
end
The problem should be clear, it only selects the part when both the X and Y sizes are positive. I understand why it doesn’t work, I just don’t know how to fix it.
I did it but I had to do it in the worst way possible
mouse.Button1Down:Connect(function()
state = true
for _, part in ipairs(folder:GetChildren()) do
if part:IsA("Part") then
table.insert(selectable, part)
end
end
local gui = selectiongui:Clone()
gui.Name = ("SelectionGui")
gui.Parent = guifolder
local frame = gui:WaitForChild("Frame")
local oldX = mouse.X
local oldY = mouse.Y
frame.Position = UDim2.new(0, oldX, 0, oldY)
while state == true do
heartbeat:Wait()
frame.Size = UDim2.new(0, mouse.X - oldX, 0, mouse.Y - oldY)
local topleftX
local topleftY
local bottomrightX
local bottomrightY
local sizeX = frame.Size.X.Offset
local sizeY = frame.Size.Y.Offset
local posX = frame.Position.X.Offset
local posY = frame.Position.Y.Offset
if sizeX ~= 0 or sizeY ~= 0 then
if sizeX > 0 then
if sizeY > 0 then
topleftX = posX
topleftY = posY
bottomrightX = posX + sizeX
bottomrightY = posY + sizeY
else
topleftX = posX
topleftY = posY + sizeY
bottomrightX = posX + sizeX
bottomrightY = posY
end
else
if sizeY > 0 then
topleftX = posX + sizeX
topleftY = posY
bottomrightX = posX
bottomrightY = posY + sizeY
else
topleftX = posX + sizeX
topleftY = posY + sizeY
bottomrightX = posX
bottomrightY = posY
end
end
else
topleftX = 0
topleftY = 0
bottomrightX = 0
bottomrightY = 0
end
for i = 1, #selectable do
local vector = camera:WorldToScreenPoint(selectable[i].Position)
print(vector.X, vector.Y)
if (topleftX < vector.X and vector.X < bottomrightX) and (topleftY < vector.Y and vector.Y < bottomrightY) then
selectable[i].SelectionBox.Visible = true
end
end
end
workspace.Folder.Part.SelectionBox.Visible = false
gui:Destroy()
print(selectable)
selectable = {}
end)