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

How to fix GUI supposed to be invisible once BoolValue is set to false?

Hello there, I have a LocalScript here where the TextButton and TextLabel's visiblity is supposed to be set to false once the BoolValue is set to false, however it does not seem to work, no output errors or whatsoever, how do I remedy this?

local plr = game:GetService("Players").LocalPlayer
local value = plr.PlayerScripts.Value
local button = script.Parent
 

	
button.MouseButton1Click:Connect(function()
 value.Value = false
end)


local function trigger()
	button.Visible = false
	plr.PlayerGui.Roll.TextLabel.Visible = false
end

if value == false then
	trigger()
end

1 answer

✓ Accepted answer

This is because you're not actually listening for the value that's getting changed. Depending on what you're trying to do there may be a better way to go about this. In this case though you could do something like this:

local Players = game:GetService("Players")
local player = Players.LocalPlayer

-- For values like these I like to put them in the character, but
-- I guess the location doesn't matter too much
local value = player.PlayerScripts:WaitForChild("Value")
local button = script.Parent

button.MouseButton1Click:Connect(function()
	value.Value = false
end)

local function trigger()
	button.Visible = false
	plr.PlayerGui.Roll.TextLabel.Visible = false
end

-- Here is where you want to setup the connection which 
-- will listen for the value being changed
value.Changed:Connect(function(newValue)
	if newValue == false then
		trigger()
	end
end)

You can read more on the Changed event here.

2 comments

0

Thanks it worked

0

Glad to hear it!

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