MouseButton1Click event won't fire?

Hello, I have an error in my script that I can’t wrap my head around.

I have a button that is supposed to fire the code when clicked, but the event never fires. The first print works but the second doesn’t. Just so you know, it is a local script parented to an image button and I have been clicking the button to test it. Here is the script:

EDIT: Sorry for using a screenshot of my code, I did not really know how to write in code format lol.

Thanks in advance!

Screenshot 2021-04-11 140858

2 Likes

Alternatively you could make this a function and connect the events like

local button = script.Parent

local function GuiStuff()
       script.Parent.BallOutline.ImageTransparency = 1
       script.Parent.BlockOutline.ImageTransparency = 0
-- you get the idea out the last 2 lines of code here 
end)


button.MouseButton1Click:Connect(GuiStuff)

Check if the button you are trying on is a button and not a label or an image label

If this happens to not work check if your GUI Button is a TextButton or ImageButton, if not that may be the issue, also make sure this is a local script and not a server script (script)

The only other instance that I see is that you parented the Gui to the workspace, while you would need to parent it to the StarterGui instead

Sorry I’m on mobile so I skim through and miss some stuff

It is an ImageButton. I do not this is an issue because MouseButton1Click is an event of ImageButton as well.

Just to be sure, do you have the Gui parented in the StarterGui? Also yes you are correct:

Yes it is parented to StarterGui.

Have you tried my method above with the function?

Yes, it yielded the same result.

You can’t change replicatedstorage values from the client I don’t think? Let me check

you can, the problem is that the event doesn’t fire whatsoever.

Can you show me a picture of where the script is under and what the parent is? I had this issue once when the script was under the button but not the screenGui

The “change” scripts work by the way.

I think there is no error in the script but I have an idea.

script.Parent.CylinderOutline.ImageTransparency = 0.5

This line may have prevented the button because of Z index. Before you click the button, Z index is invalid but after you change the transparency of the image, the button must have gone under the image. If this image and button is overlapping, maybe z index is causing it.

Try changing the Z index of the image buttons. Block’s z index must be higher than others.

That is a great idea! I will try it.

1 Like

No, it still didn’t work. I set the ZIndex high.

Nevermind it worked, Thanks so much!

1 Like