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

How do i detect if a gui touched a another gui / another gui is inside of it?

Asked by 4 years ago

I have a gui, and i wanna detect when another gui touches it or is inside of it

How can i do so?

1 answer

Log in to vote
0
Answered by
Nowaha 459 Moderation Voter
4 years ago
Edited 4 years ago

I have found this function on another question.

function collidesWith(gui1, gui2)
    local gui1_topLeft = gui1.AbsolutePosition
    local gui1_bottomRight = gui1_topLeft + gui1.AbsoluteSize

    local gui2_topLeft = gui2.AbsolutePosition
    local gui2_bottomRight = gui2_topLeft + gui2.AbsoluteSize

    return ((gui1_topLeft.x < gui2_bottomRight.x and gui1_bottomRight.x > gui2_topLeft.x) and (gui1_topLeft.y < gui2_bottomRight.y and gui1_bottomRight.y > gui2_topLeft.y)) 
end

It should also work for your situation! Just check this everytime the GUI moves.

Ad

Answer this question