Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How Do I Change "Gui.Visible" to False When It Becomes True?

Hello there,

I want to make a text label not be visible anymore 3 seconds after it becomes visible. This is what I have in a localscript as a child of the text label (referred to as "CoinsEarned").

local CoinsEarned = script.Parent

CoinsEarned:GetPropertyChangedSignal("Visible"):Connect(function()
	if CoinsEarned.Visible == true then
		wait(3)
		CoinsEarned.Visible = false
	end
end)

For some reason, this works the first time. However, as soon as the text label becomes visible for a second time, it never shows up.

Thanks in advance!

1 comment

0

Why would you want to do this??? This should work.

1 answer

That's because now, after the first time, CoinsEarned.Visible is now false thus the if statement won't be used,

I suggest using else or elseif.

Sample of using else

local a = true -- you can change this to false for testing

if a==true then
	a = false
	print('a is now false')
else
	a = true
	print('a is now true')
end

Sample of using elseif

local a = true -- you can change this to false for testing

if a==true then
	a = false
	print('a is now false')
elseif a==false then
	a = true
	print('a is now true')
end

Another option for inverting a boolean using the logical operator not (you may still need the if statement if you are doing more stuff than just inverting a boolean)

local a = true -- you can change this to false for testing

print('a is ',a)
a = not a
print('a is now',a)

1 comment

0

Not what OP wanted, but nice effort

This discussion is preserved as it was. New answers, comments, and votes are closed.