Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
R0jym 47
2 years ago
Edited 2 years ago

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

Log in to vote
0
Answered by 2 years ago

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.

0
Thanks it worked R0jym 47 — 2y
0
Glad to hear it! SimpleFlame 255 — 2y
Ad

Answer this question