Script not working!

Here’s my code:

local Search_Bar = game.Players.LocalPlayer.PlayerGui["Game UI"].HomeScreen.Background.Search["Search Bar"]

local function Search()
    Search_Bar:GetPropertyChangedSignal("Text"):Connect(function()
        if Search_Bar.Text ~= "" then
            warn("0")
            game.StarterGui["Game UI"].HomeScreen.Background.ScrollingFrame.Animals.Visible = false
            game.StarterGui["Game UI"].HomeScreen.Background.ScrollingFrame.Brands.Visible = false
            game.StarterGui["Game UI"].HomeScreen.Background.ScrollingFrame.Celebrity.Visible = false
            game.StarterGui["Game UI"].HomeScreen.Background.ScrollingFrame.Food.Visible = false
            game.StarterGui["Game UI"].HomeScreen.Background.ScrollingFrame.Games.Visible = false
            game.StarterGui["Game UI"].HomeScreen.Background.ScrollingFrame["General Knowledge"].Visible = false
            game.StarterGui["Game UI"].HomeScreen.Background.ScrollingFrame.Geography.Visible = false
            game.StarterGui["Game UI"].HomeScreen.Background.ScrollingFrame.History.Visible = false
            game.StarterGui["Game UI"].HomeScreen.Background.ScrollingFrame.Literature.Visible = false
            game.StarterGui["Game UI"].HomeScreen.Background.ScrollingFrame.Math.Visible = false
            game.StarterGui["Game UI"].HomeScreen.Background.ScrollingFrame.Movies.Visible = false
            game.StarterGui["Game UI"].HomeScreen.Background.ScrollingFrame.Music.Visible = false
            game.StarterGui["Game UI"].HomeScreen.Background.ScrollingFrame.Riddles.Visible = false
            game.StarterGui["Game UI"].HomeScreen.Background.ScrollingFrame.Science.Visible = false
            game.StarterGui["Game UI"].HomeScreen.Background.ScrollingFrame.Sports.Visible = false
            game.StarterGui["Game UI"].HomeScreen.Background.ScrollingFrame.Tech.Visible = false
        elseif Search_Bar.Text == "" then
            warn("1")
        end
    end)
end

Search()

Here’s the Explorer:

image

Here’s the Output:

image

With all this information we can tell that the script is working properly but the elements that were supposed to become invisible still stayed visible.

What is wrong with my script? :thinking:

You’re changing the game’s StarterGui. Any changes will only appear after the player’s gui has been reset.