Mouse. Button1Down is not working when i use it on a gui

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

local function mouseClick()
	print ("hi")
end

mouse.Button1Down:Connect(mouseClick)

when I use this in the game it works but when i try to click on a gui in the game, it prints the message no more. How do you fix it?

1 Like

try this

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
Mouse.Button1Down:Connect(function()
print("Hi")
end)

oh you’re trying to do it to guis also, then you can always do a script for all guis or find a better way

exampe (a local script for the gui) :

script.Parent.MouseButton1Click:Connect(function()  -- button you want to connect
print("hi")
end)

Use:

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		print("ButtonDown")
	end
end)

UIS.InputEnded:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		print("ButtonUp")
	end
end)
5 Likes

actually use, @ancadejo10 's solution i never thought about somehing like that

thank you this works. But just wondering why can’t the mouse.Button1Down work on gui’s also?

It doesn’t for guis you use MouseButton1Click in a local script. Let’s say it’s in the button then like this:

script.Parent.MouseButton1Click:Connect(function()
    print("Clicked")
end)
1 Like

thats exactly what i wanted to tell him