GameProcessedEvent

I want to check if the the GameProcessedEvent is true or not, without firing the InputBegan or Fired Events, is this possible?

I have a RenderStepped Event that is tracking the placement of a unit, but I want to make it so that if the player clicks a button the unit doesn’t track to where the button is. This only happens on mobile, so I don’t really know how to fix it

So you basically want to check if the mouse is on a button?

Here’s a method:

local uis = game:GetService("UserInputService")
local playerGui = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui")

local function isOccupyingElements()
    local position = uis:GetMouseLocation() --get location relative to top left
    return #playerGui:GetGuiObjectsAtPosition(position.X, position.Y) > 0 --return whether or not 0 objects are at the position
end

--example usage
if isOccupyingElements() then
    print("Mouse is in gui elements!")
end
1 Like

It returns true even though the player isn’t in any game elemtn

Also is this not just checking if the mouse is within the client’s screen?

If it doesn’t work, why marked as solved? Just asking…

Do you have any fullscreen invisible gui objects that are in the way? If yes, you might need to create a blacklist and make sure that the returned table from PlayerGui:GetGuiObjectsAtPosition() only contains those elements, if it contains elements at all.


No, so basically GetGuiObjectsAtPosition will return any gui items at the given position, by using the mouse position we can detect gui objects on the mouse.

I thought about what that :GetGuiObjectsAtPosition() function does, and thought I could fix it using that, but I ran into an issue: even if the mouse of the client is on the button it still returns false, and if it is a barely on it then it will return true

And also yes I do have some invisible ones, but I rewrote the code so that it only checks for 3 GuiObjects

local function isOccupyingElements()
    local position = UserInputService:GetMouseLocation()
    local Objects = PlayerGui:GetGuiObjectsAtPosition(position.X, position.Y)
    if table.find(Objects,MobileSupport["Brawler Support"].Place) or table.find(Objects, MobileSupport["Brawler Support"].Cancel) or table.find(Objects, MobileSupport["Brawler Support"].Rotate) then
        return true
    end
end

Ok, that’s odd behaviour. I don’t really know how to fix that, sorry. I’ll let you know if I think of a solution.

So I found this: How do I detect if the mouse is inside a frame?

And using it I used this code:

local function isOccupyingElement(GuiElement : TextButton)
    local PointAVector = GuiElement.AbsolutePosition
    local PointBVector = GuiElement.AbsolutePosition + MobileSupport["Brawler Support"].Place.AbsoluteSize
    
    local PointA = UDim2.fromOffset(PointAVector.X,PointAVector.Y)
    local PointB = UDim2.fromOffset(PointBVector.X,PointBVector.Y)
    
    local mouseVector = Vector2.new(Mouse.X,Mouse.Y)
    local pointAVector = Vector2.new(PointA.X.Offset,PointA.Y.Offset)
    local pointBVector = Vector2.new(PointB.X.Offset,PointB.Y.Offset)
    return ((mouseVector.X > pointAVector.X and mouseVector.Y > pointAVector.Y) and (mouseVector.X < pointBVector.X and mouseVector.Y < pointBVector.Y))
end

And it worked fine