ImageLabel transparency script not working

Hey everyone, so I made a script today that is supposed to show an image with a fade in and out on a button click. It doesn’t work for some reason and idk why, I would really appreciate your help!


local GUI = script.Parent.Parent
local Image = game.StarterGui.UpdateGUI.PathChosen


script.Parent.MouseButton1Click:Connect(function()
	if GUI.Toggle.Value == false then
		GUI.Toggle.Value = true
		for i = 1,100 do
			Image.ImageTransparency -= 0.01
			wait(0.01)
		end


	elseif
		GUI.Toggle.Value == true then
		GUI.Toggle.Value = false
		for i = 1,100 do
			Image.ImageTransparency += 0.01
			wait(0.01)
		end
	end
end) 
1 Like

What’s not working? Are you getting errors? Is it not turning transparent? or is it, but it’s not going at the right speed?

I’d suggest throw a few print commands in your click connect to see where the problem begins, once you dont see a print command come up in console then you’ll have an idea where to start diagnosing

you typed elseif instead of else

elseif(else here)
		GUI.Toggle.Value == true then
		GUI.Toggle.Value = false

if think it’s because you forgot to define the player in the script but I am not 100% sure. most MouseButton1Click functions that are used in UI define the player kinda like this: local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()

script.Parent.Parent.Visible = false

end)

or in your case:
local player = game.Players.LocalPlayer
local GUI = script.Parent.Parent
local Image = game.StarterGui.UpdateGUI.PathChosen

script.Parent.MouseButton1Click:Connect(function()
if GUI.Toggle.Value == false then
GUI.Toggle.Value = true
for i = 1,100 do
Image.ImageTransparency -= 0.01
wait(0.01)
end

else
	GUI.Toggle.Value == true then
	GUI.Toggle.Value = false
	for i = 1,100 do
		Image.ImageTransparency += 0.01
		wait(0.01)
	end
end

end)

you are chaning transparency of StarterGUI not PlayerGui

oh, sorry :smile: I got it a bit confused

2 Likes

local GUI = script.Parent.Parent
local plr = game.Players.LocalPlayer
local Image = plr.PlayerGui.UpdateGUI.PathChosen


script.Parent.MouseButton1Click:Connect(function()
	if GUI.Toggle.Value == false then
		GUI.Toggle.Value = true
		for i = 1,100 do
			Image.ImageTransparency -= 0.01
			wait(0.01)
		end


	else
		GUI.Toggle.Value == true then
		GUI.Toggle.Value = false
		for i = 1,100 do
			Image.ImageTransparency += 0.01
			wait(0.01)
		end
	end
end) 

here is new fixed script

what is she trying to change exactly?

Transaprency I guess
“Hey everyone, so I made a script today that is supposed to show an image with a fade in and out on a button click. It doesn’t work for some reason and idk why, I would really appreciate your help!”

if that is what she said I think she is trying to do it with a labelbutton which is basically what i ment.

but idk really what she is trying do :person_shrugging:

I am trying to change the transparency of an imagelabel with a button click, when clicked once it appears, when clicked again it disappears

aren’t they the same thing tho

It says this for some reason
image

Ahhh! I get it now! You should probably use one of our scripts; if they don’t work tell us.

You forgot to add an “if” statement. If that was not your intention you should not have used “then”.

ooh i didn’t notice that, the original script had elseif instead of else, i’ll test it now

I am new to scripting myself so I am helping as much as I can :smiley:

oops I made mistake sorry

local GUI = script.Parent.Parent
local plr = game.Players.LocalPlayer
local Image = plr.PlayerGui.UpdateGUI.PathChosen


script.Parent.MouseButton1Click:Connect(function()
	if GUI.Toggle.Value == false then
		GUI.Toggle.Value = true
		for i = 1,100 do
			Image.ImageTransparency -= 0.01
			wait(0.01)
		end


	else 
		GUI.Toggle.Value == true 
		GUI.Toggle.Value = false
		for i = 1,100 do
			Image.ImageTransparency += 0.01
			wait(0.01)
		end
	end
end)