Check if a player clicked out of a image label

Can you print the input? It should definitely detect Mouse Inputs.

Is the issue that the game processed event is false?

No, as I did a print(mouse stat) whenever the mouse leave to enters.

From what did you infer that the game couldn’t figure out the input?

I’m not too sure.It could be something inside the script. Do you mind pasting the script and testing it?

I do not really understand what the issue is, which part of the code code doesn’t run correctly?
Try printing out Input.UserInputType.

I think I’m getting what’s wrong now. Whenever I click on the ui, the game observes it, however, when I click out, it doesn’t

Then just check whether mouseStat equals false.

if input.UserInputType == Enum.UserInputType.MouseButton1 and mouseStat == true then
1 Like

Why not just do,

if gameProcessed then
	return
end

Edit: Here, try this:

UIS.InputBegan:Connect(function(input, gameProcessed)
	if gameProcessed then
		return
	end
	if input.UserInputType == Enum.UserInputType.MouseButton1 and gameProcessed == false then
		game.Players.LocalPlayer.PlayerGui.OrderingUI.ImageLabel:TweenPosition(UDim2.new(0.5, 0, 0.5, 0))
		game.Players.LocalPlayer.PlayerGui.OrderingUI.Receipt:TweenPosition(UDim2.new(0.913, 0, 0.5, 0))
	end
end)
1 Like

Was the problem fixed or still not?

No, it’s still not fixed. I’ll see if I can fix it. Do you have any idea what’s wrong with it?

I can’t really help as I am still unaware regarding what the issue is.

You need to hook/unkhook the mouse click event whenever the image label is unfocused/focused respectively.

local players = game:GetService("Players")
local player = players.LocalPlayer
local mouse = player:GetMouse()

local imageLabel = script.Parent

local function onMouseButtonDown()
	print("Hello world!")
end

local connection
connection = mouse.Button1Down:Connect(onMouseButtonDown)

local function onImageMouseEnter()
	if connection.Connected then connection:Disconnect() end
end

local function onImageMouseLeave()
	connection = mouse.Button1Down:Connect(onMouseButtonDown)
end

imageLabel.MouseEnter:Connect(onImageMouseEnter)
imageLabel.MouseLeave:Connect(onImageMouseLeave)
1 Like

This sadly only works once. I can’t tween the ui back into the player’s screen.

The connection is disconnected/reconnected whenever the player’s mouse cursor enters/leaves the ImageLabel instance respectively.

It’ll work repetively, I can only assume you’ve made a mistake in your implementation.

image

The ui leaves the player’s screen fully, so the system thinks that the player isn’t hovering over it, I think.

local players = game:GetService("Players")
local player = players.LocalPlayer
local mouse = player:GetMouse()

local imageLabel = script.Parent

local function onMouseButtonDown()
	if script.Parent.Position == UDim2.new(0.5, 0, 0.5, 0) then
		print("hi")
		script.Parent.Parent.Receipt:TweenPosition(UDim2.new(1.096, 0, 0.5, 0, Enum.EasingStyle.Elastic, Enum.EasingDirection.Out, 3))
		script.Parent.Parent.ImageLabel:TweenPosition(UDim2.new(.5, 0, 1.4, 0, Enum.EasingStyle.Elastic, Enum.EasingDirection.Out, 3))
	end
end

local connection
connection = mouse.Button1Down:Connect(onMouseButtonDown)

local function onImageMouseEnter()
	if connection.Connected then 
		connection:Disconnect()
	end
end

local function onImageMouseLeave()
	connection = mouse.Button1Down:Connect(onMouseButtonDown)
end

imageLabel.MouseEnter:Connect(onImageMouseEnter)
imageLabel.MouseLeave:Connect(onImageMouseLeave)

It does work, if I don’t tween the UI out of the player’s screen

Do you know how I can fix the fact that it thinks that the mouse left the uni when the ui is actually out of the player’s screen.