How do i check if my mouse isn't on any of the ui ingame?

I want to make it so my mouse can only click on places that aren’t ui objects. Is it possible?

3 Likes

This is definitely possible. If they aren’t text buttons you could disable them for that moment. with a Boolean or something.

Could you add a bit more context for me?

2 Likes

I am making a clicker game and i don’t want to get clicking effects to appear when my mouse is on ui, since it will be annoying. So that is basically what i want to do

2 Likes

If you want to ensure that the mouse is hovering over a gui Element, PlayerGui has a function called :GetGuiObjectsAtPosition(). Here is a LocalScript that will tell you if the mouse is on a gui element:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

Mouse.Move:Connect(function()
	local MousePos = game:GetService("UserInputService"):GetMouseLocation() - game:GetService("GuiService"):GetGuiInset()
	local getGUI = Player:WaitForChild("PlayerGui"):GetGuiObjectsAtPosition(MousePos.X,MousePos.Y)

	if #getGUI ~= 0 then 
		print("hovering over a gui!") 
	end
end)
4 Likes

So far i can think only of making something like this:

script.Parent.ClickDetector.MouseClick:Connect(function(object)
	if object:IsA("Frame") then
		-- do nothing
	elseif not object:IsA("Frame") then
		print("tested")
	end
end)

Or you can use ClassName.

I have never made a clicker game so im not sure how to structure it so i used a click detector.

2 Likes

Yeah this probably would work better than my idea.

2 Likes

I tried this, and it works thank you! :slight_smile:

1 Like

Even I learned something new! :star_struck:

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.