Loops and UserInputService in relation to GUI?

Is there any way you can run a for loop and then detect which buttons in the loop you’re able to like this?
As you can see below, it is using MouseButton1Click, is there a way of doing this similarly, but with UserInputService?
Note: I’m trying to make a inventory that has drag and drop equipping slots.

for i, v in pairs(script.Parent:GetChildren() do
   if v:IsA("ImageButton") then
      v.MouseButton1Click:Connect(function()
         --do stuff here
      end)
   end
end

Do you mean:

for i, v in pairs(script.Parent:GetChildren() do
   if v:IsA("ImageButton") then
      UserInputService.InputBegan(function()
         --do stuff here
      end)
   end
end
1 Like

It seems you’ve helped me out, thank you mate