Gui isn't lighting up when my mouse runs over it

Hello I’ve recently been starting to learn scripting and gui topics but I’ve been hitting bumps that i cant find solutions to.
I’m trying to make a gui that when my mouse hovers over the button either the image lights up or another type of effect for this to seem as it lights up ill go what ever the best solution as it doesn’t need to be perfect

here is what my gui looks like its image labels too https://i.gyazo.com/5d9f9eed2cd732ce4822435b4680ccdd.gif

this is my code


script.Parent.MouseButton1Click:Connect(function()

Highlight.ImageTransparency = .5

end)

script.Parent.MouseButton1Click:Connect(function()

Highlight.ImageTransparency = 0

end)

it works but not the way i want, as it simply doesnt change but when i click on it it dulls out to .5 i want to to light up when my mouse is over it and dull down or go back to normal when my mouse moves off it, thanks again for your time!

right now, when you click the script.parent, 2 click events are firing at the same time, so you are both setting its transparency to 0.5 and 0 in the same frame.

maybe try

script.Parent.MouseButton1Click:Connect(function()
    Highlight.ImageTransparency = .5
    wait(0.1)
    Highlight.ImageTransparency = 0
end)

edit2: oh I just read the last sentence in your post, yes do LegendOJ1’s solution

You can use the MouseEnter and MouseLeave functions to achieve this.

Example of how to use these:

script.Parent.MouseEnter:Connect(function()
    Highlight.ImageTransparency = .5
end)

script.Parent.MouseLeave:Connect(function()
    Highlight.ImageTransparency = 0
end)

Hope this helped.

2 Likes

thank you for helping out but when i do it and hit run it gives me the following message
14:01:37.964 - Players.Troublemaiker.PlayerGui.ScreenGui.Frame.ChaptersButton.LocalScript:6: attempt to index nil with ‘ImageTransparency’

that means Highlight is nil, make sure that is set to something

1 Like

sorry to drag this on, but could you explain that just a bit more!

local Highlight = --the path to the highlight ui

script.Parent.MouseButton1Click:Connect(function()
    Highlight.ImageTransparency = .5
    wait(0.1)
    Highlight.ImageTransparency = 0
end)

Not sure if you’re talking about mover hovering but if you are:
Note: This might be out of order, if so just rearrange it

script.Parent.script.Parent.MouseLeft:Connect(function()

	Highlight.ImageTransparency = .5

end)

script.Parent.script.Parent.MouseLeave:Connect(function()

	Highlight.ImageTransparency = 0

end)

It is about hovering but i think im just having an issue about understanding the Highlight part.

script.Parent.MouseEnter:Connect(function()
    script.Parent.ImageTransparency = 0.5 -- this will run when the mouse hovers over
end)

script.Parent.MouseLeave:Connect(function()
    script.Parent.ImageTransparency = 0 -- this will run when the mouse leaves the button
end)

MouseEnter means when your mouse hovers over.
MouseLeave means when your mouse stops hovering over.

1 Like

Oh please for the love of roblox API stop using MouseButton1Click. Use activated

thank you for helping guys I’m sorry I was struggling about the topic but still, thank you so much.

1 Like