My script is supposed to detect a click on any of the gui in a frame. The clicks aren’t being detected though; any help? Thanks!
for i, item in pairs(script.Parent:GetChildren()) do
if item ~= script then
item.MouseButton1Click:Connect(function()
print(1)
SellFocus(item)
print(2)
end)
end
end
Only Buttons can receive mouse pressed events (buttons being TextButtons and ImageButtons). What you may want to do, if you’re only looking for Buttons for the player to click, then you could just do this:
for i, item in pairs(script.Parent:GetChildren()) do
if item:IsA("TextButton") or item:IsA("ImageButton") then
item.MouseButton1Click:Connect(function()
print(1)
SellFocus(item)
print(2)
end)
end
end
Are the GUI elements either TextButtons or ImageButtons? Only objects which are Gui Buttons can actually detect MoustButton1Down, MouseButton1Click, and etc.
I just tested out the code in studio and got it to work fine. Make sure the script you’re using is a LocalScript if it’s not. The ImageButtons need to be directly parented to the script’s parent as well, and not be, for instance, parented to a frame parented to the script’s parent.