Deactivate a function when my menu is deactivated

Hello what is the error of this code?

if MenuGui.Visible == false
then
script.Parent.Parent.Parent.Parent.IgnoreGuiInset = false
pcall(function()
local starterGui = game:GetService('StarterGui')
starterGui:SetCore("TopbarEnabled", true)
end)
end

I already have the code execute in true

script.Parent.Parent.Parent.Parent.IgnoreGuiInset = false
and

pcall(function()
local starterGui = game:GetService('StarterGui')
starterGui:SetCore("TopbarEnabled", true)
end)

in false

Does it return any errors? What is this code supposed to do and what is the problem with it? Please provide the necessary information.

hello, sorry I think I marked it (I wrote it on Google translation because I’m French and I had to forget to copy it) so it’s the code to deactivate the topbar so that my game menu takes everything the screen but I would like it to reactivate once my menu is no longer visible

I think I understand where you are coming from, try and use :SetTopbarTransparency, as seen in this thread,. Also displayed in this (I admit copied from that thread) example,

local playerGui = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui")
 
playerGui:SetTopbarTransparency(1)

I would like that if my menu = not visible its execute a code, and if it is visible its execute another code

:SetTopbarTransparency() is now deprecated since the old topbar was removed.

1 Like
if game.StarterGui.MenuGui.Enabled == true then
pcall(function()
local starterGui = game:GetService('StarterGui')
starterGui:SetCore("TopbarEnabled", false)
end)
else if game.StarterGui.MenuGui.Enabled == false then
pcall(function()
local starterGui = game:GetService('StarterGui')
starterGui:SetCore("TopbarEnabled", true)
end)
end
end

it does not work …

can you fix it?

@DonooZeus First you should learn to write a script. Second, I don’t really understand what your problem is. Do you even know what pcall does and what you get an error message in the output?

So I would like to try to help you, but because I don’t know your problem and therefore don’t know where I could improve your code, don’t admit anything. You really not need pcall, only use this if you know what this does. If not then you can google.

when my game starts I deactivate the toolbar so that my menu takes up the whole screen


so now I would like to activate it when the menu is no longer activated


because suddenly after there is no longer the menu I have more the topbar (cat and others)

1 Like

It looks like you need Debounce to solve this problem:

I can’t seem because I’m French and I don’t understand

1 Like

@DonooZeus, i think i understand your proble:

You are controlling if the Gui from StarterGuiService is enabled, but you need to controll the Gui from the PlayerGui folder:

local Player = game.Players.LocalPlayer
if Player.PlayerGui.MenuGui.Enabled == true then
pcall(function()
local starterGui = game:GetService('StarterGui')
starterGui:SetCore("TopbarEnabled", false)
end)
else if Player.PlayerGui.MenuGui.Enabled == false then
pcall(function()
local starterGui = game:GetService('StarterGui')
starterGui:SetCore("TopbarEnabled", true)
end)
end
end

This is the solution to your problem:
You control the MenuGui in the server, but everything in the StarterGui is copied to the PlayerGui of each player. So everything in the StarterGui remains unchanged in other words:
You must always control in PlayerGui, never in StarterGui.