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

1 Like

you typed elseif instead of else

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

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)

1 Like

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)

1 Like

you are chaning transparency of StarterGUI not PlayerGui

1 Like

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

3 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

1 Like

what is she trying to change exactly?

1 Like

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!”

1 Like

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

1 Like

but idk really what she is trying do :person_shrugging:

1 Like

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

1 Like

aren’t they the same thing tho

1 Like

It says this for some reason
image

1 Like

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

1 Like

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

1 Like

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

1 Like

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

1 Like

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) 
1 Like