Mouse Inputs Going Through GUI

Here I have a place-able drink!! :cup_with_straw:

Pretty simple to understand, the player’s mouse is going through the GUI.
How can I prevent that?
I have tried using frames, messing around with the properties tab, nothing worked… :pensive:

Here an example:

Set the property active to true on the frame

1 Like

I have already done it, no results!!

Oh i think the problem is that you can’t click ui buttons while holding a tool

1 Like

Players are required to press on the confirm button too br placed, so it does work

What are you using to detect the mouse input? If it’s UserInputService, you can use the processed event to check whether a UI element was clicked.

local uis = game:GetService("UserInputService")

local function onInput(input:InputObject, processed:boolean)
    if processed then return nil end
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
        --do stuff
    end
end

uis.InputBegan:Connect(onInput)
1 Like

That work? Thought it was only for computer keyboard inputs😧

( i will try it when i get home!!!)

the gameProcessedEvent still works for mobile, and I’m pretty sure a mobile touch fires MouseButton1 input, it also works for UI buttons (MouseButton1Down, MouseButton1Up, MouseButton1Click). Give it a go, it can do no harm.

1 Like

I really suggest you use UserInputService than clicking since its much more preferred by players, if you want you could use ContextActionService especially on Mobile. If you can’t find a proper solution the best way is to delete the UI/Frame and remake it, sometimes settings might change without you noticing. Anyways good luck making this game, it looks nice!

1 Like

Alright, good luck! If it works, make sure to mark this topic as solved so it can close.

It was by accident :joy: I am on my phone, navigating is hard

1 Like

it worked!!!
But, not really… :hushed:

The Mouse now stops going through button, but I don’t know how I would make it to directly place the drink.

Once you press on place button, it doesn’t directly runs the RemoteEvent:FireServer(mouseHit).

The player will need to interact with the world space again in order to continue the function. Which then, making the placement to be relocate to that new position.

How would I fix this?

local inputConnection

local function placeObject()
    isPlacingModeOn = false
    if WholeScreenGui then
        WholeScreenGui:Destroy()
    end



    local previewFolder = game.Workspace:FindFirstChild("PreviewFolder")
    if previewFolder then
        previewFolder:Destroy()
    end
    RemoteEvent:FireServer(mouse.Hit)
end



PlaceButton.MouseButton1Down:Connect(function()
   
    if not inputConnection then
        inputConnection = InputService.InputBegan:Connect(function(input, gameprocess)
            if not gameprocess and input.UserInputType == Enum.UserInputType.Touch then
                placeObject()
                inputConnection:Disconnect()
                inputConnection = nil
            end
        end)
    end
end)

Maybe make the processed event update a Boolean or other variable to use?

Can you explain a bit more about the process? I don’t really get it. Do you want to click to place, then click button and it places there?

1 Like

You have the idea correct!!

Button 1: Placing mode toggle
Button 2: Confirm placement

Placing toggle is to enable and disable the placing mode.

The player can drag across the surface to choose where they would like to place, then they hit the confirm button, simple!

(Gameprocess parameters is sooo confusing for mobile guis…:sob::sob::sob:)

The gameProcessedEvent just detects if a UI element is clicked.

I’d say probably move the input detection outside of the MouseButton1Down connection because it’s only running in there, and then it listens for the input detection. Control it with a Boolean instead, it also means you don’t have to disconnect yet another connection.

In short: You are listening for the mouse input after the button is pressed, which is why you need to click again.

1 Like

Took me a while to understand that, I will try it out once I’m home, thank you very much for being so patient for me :flushed::pray:t2:

2 Likes

I tried it! No results still, same problem:
:star::sparkler::sparkles::sparkles:

This is the most challenging code I’ve done, I don’t think there is a solution to this…

Here is my updated code:

local inputListening = false
local inputConnection

local function placeObject()
	isPlacingModeOn = false
	if WholeScreenGui then
		WholeScreenGui:Destroy()
	end

	local previewFolder = game.Workspace:FindFirstChild("PreviewFolder")
	if previewFolder then
		previewFolder:Destroy()
end



RemoteEvent:FireServer(mouse.Hit)
end

local function handleInput(input, gameprocess)
	inputListening = false
	if not gameprocess and input.UserInputType == Enum.UserInputType.Touch then
		placeObject()
		inputConnection:Disconnect()
		inputConnection = nil
		
	end
end

PlaceButton.MouseButton1Down:Connect(function()
	if not inputListening then
		inputListening = true
		inputConnection = InputService.InputBegan:Connect(handleInput)
	end
end)

(I feel soooo dumb right now!!! :sleepy:)

dONT WORRYi CAME TO HELP.What is the Issue right now,Explain even more because i seem not to understand what u mean

I see the issue on what happening

Firstly,I think u have to reset the position because i think it will

and also the input listening is been set to false again. because of the input connection line

try doing inputConnection = nil first

Actually There is no problem,It just that the system takes a while to load due to the gameprocess

u print the gameprocess and see what it displays because your script is actually alright