InputBegan not working on buttons

It never prints MouseButton1 when I click the button :confused: I need to use InputBegan, as I need to pass the input. But it only prints MouseMovement (when mouse enters) but never clicking

for _, slot in HUD.Inventory.Content.Main.Hotbar:GetChildren() do
		if not slot:IsA("ImageButton") then continue end
		
		SlotController:Create(slot)
		print(1)
		--// Dragging
		slot.InputBegan:Connect(function(input)
			print(input.UserInputType)
			if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then				
				print(1)
				DragController:Start(input, slot.Content)
			end
		end)
	end

image

Please read my post fully before commeting

1 Like

What do you exactly need from the input? There could help a different approach.

So I can then use InputChanged, which will fire when that specific input has changed, as well as get the inputs position.

I don’t see any reason to change what I have. What I have should theoretically work, so unless this is a new Roblox bug

Is this UI supposed to be a scroll bar? If so i have working code for a scroll bar

You can use UserInputService and connect / disconnect the function when the mouse enters / leaves the imageButton

No, for dragging UI elements

more text for characters

That’s not what I’m wanting. What I have has worked in the past. It’s just now that it’s decided to stop working

1 Like

Does input.UserInputType print? And what does it print

Boolean expression logic mistake.

if not (slot:IsA("ImageButton")) then continue end

That’s definately the issue. I do this everywhere, the extra brackets are not necessary. It’s also printing the mousemovement inputbegan, so it’s definately firing

It does, it only prints MouseMovement

1 Like

image

https://developer.roblox.com/en-us/api-reference/event/GuiButton/Activated
You may want to opt to use the ‘Activated’ event/signal of ‘GuiButton’ instances instead, it passes an ‘InputObject’ object to any connected callback functions.

Kind of unrelated but your script is defining InputBegan multiple times which isn’t needed and increases lag.