Script which is triggered by a BoolValue doesnt work even if BoolValue is set to true

local power = game.StarterGui.NXTChampionshipTitleMatch.TitlePower.Value

 if power == "true" then

script.Parent.ImageLabel.Visible = true

script.Parent["NXT TITLE MATCH"].Visible = true

else

script.Parent.ImageLabel.Visible = false

script.Parent["NXT TITLE MATCH"].Visible = false

end

This script is suppose to set the ImageLabel and TexTlabel visible when BoolValue is true, but it doesnt work.
I have tried a local script and a normal script, but neither seem to work. Can somebody help me please?

This is because when Roblox starts a game, StarterGui just holds a master copy of your Gui, Players get a copy.

So in a LocalScript:

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
local Power = PlayerGui:WaitForChild("NXTChampionshipTitleMatch").TitlePower 
-- Accessing the value in the if statement is better practice

local Image = script.Parent.ImageLabel -- Reference UI Elements for easy access
local TitleMatch = script.Parent["NXT TITLE MATCH"]
if Power.Value then -- Testing for booleans, as booleans are not resolvable to strings
     Image.Visible = true
     TitleMatch.Visible = true
else
     Image.Visible = false
     TitleMatch.Visible = false
end

Hope this helps!

EDIT:
if Power.Value then is equivalent to if Power.Value == true then
if SOMETHING then can also check to see if something exists.
Example:

if script.Parent:FindFirstChild("Name") then
     print("script.Parent.Name exists!")
else
     print("script.Parent.Name doesn't exist.")
end
1 Like

I’ve got another local script which activates the power and changes the boolvalue to true, but the imagelabel and textlabel doesnt show up.

This is because you’re not actively searching for if the value changes, you’ll need to connect an event for when the Bool changes:

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
local Power = PlayerGui:WaitForChild("NXTChampionshipTitleMatch").TitlePower 
-- Accessing the value in the if statement is better practice

local Image = script.Parent.ImageLabel -- Reference UI Elements for easy access
local TitleMatch = script.Parent["NXT TITLE MATCH"]

Power.Changed:Connect(function() -- Connect an anonymous function to the BoolValue.Changed event
     if Power.Value then -- Testing for booleans, as booleans are not resolvable to strings
          Image.Visible = true
          TitleMatch.Visible = true
     else
          Image.Visible = false
          TitleMatch.Visible = false
     end
end)

Doesn’t work, heres the script I put it into.
local HttpService = game:GetService(“HttpService”)

local data = HttpService:JSONDecode(script.CutsceneData.Value)

local c = game.Workspace.CurrentCamera

local rs = game:GetService(“RunService”).RenderStepped

local Players = game:GetService(“Players”)

local Player = Players.LocalPlayer

local PlayerGui = Player:WaitForChild(“PlayerGui”)

local Power = PlayerGui:WaitForChild(“NXTChampionshipTitleMatch”).TitlePower

local Image = script.Parent.ImageLabel – Reference UI Elements for easy access

local TitleMatch = script.Parent[“NXT TITLE MATCH”]

Power.Changed:Connect(function() – Connect an anonymous function to the BoolValue.Changed event

if Power.Value then – Testing for booleans, as booleans are not resolvable to strings

Image.Visible = true

TitleMatch.Visible = true

else

Image.Visible = false

TitleMatch.Visible = false

end

end)

function tweenCam(c1, f1, time, fov, roll)

local c0,f0,fv0,r0,frames = c.CoordinateFrame,c.Focus,c.FieldOfView,c:GetRoll(),time/0.015

for i = 1,frames do

c.CameraType = “Scriptable”

c.CoordinateFrame = CFrame.new(c0.p:lerp(c1.p,i/frames),f0.p:lerp(f1.p,i/frames))

c.FieldOfView = (fv0+(fov-fv0)(i(1/frames)))

c:SetRoll(r0+(roll-r0)(i(1/frames)))

rs:wait()

Power.Value = true

end

end

print(“Running”)

c.CameraSubject = nil

c.CameraType = “Scriptable”

c.CoordinateFrame = CFrame.new(unpack(data[1].c1))

c.Focus = CFrame.new(unpack(data[1].f1))

c.FieldOfView = data[1].FOV

c:SetRoll(data[1].Roll)

if script:findFirstChild(“SkipCutsceneGuiValue”) then

local gui = script.SkipCutsceneGui:clone()

gui.Parent = game.Players.LocalPlayer.PlayerGui

gui.Cutscene.Value = script

gui.Main.Debug.Disabled = false

script.SkipCutsceneGuiValue.Value = gui

end

for i = 2,#data do

tweenCam(CFrame.new(unpack(data[i].c1)),CFrame.new(unpack(data[i].f1)), data[i].step, data[i].FOV, data[i].Roll)

end

c.CameraSubject = game.Players.LocalPlayer.Character.Humanoid

c.CameraType = “Custom”

c.FieldOfView = 70

if script:findFirstChild(“SkipCutsceneGuiValue”) then

if script.SkipCutsceneGuiValue.Value ~= nil then

script.SkipCutsceneGuiValue.Value:Destroy()

Power.Value = false

end

end

script:Destroy()

Can you please correctly tab your code and put it in a code block? This is near impossible to read.