GUI calling a nil value

is this in a local script or server script, and where did you place this script in?

It doesnt show any errors? you could try placing the scripts inside the frame, though, i would make both scripts into just one, since you can make it pretty easily, uhhhh, ill try to make it work wait me a sec :wink:

So, this is how ill do it, i’ll explain everything

Sorry if this seems like a lot of text but trust me, it would help a lot if you read everything, also, remember to change the info here to be accord to your project, or else it wont work

(Also, this script is a local script, so it only happens to the player who activated the button AND it is inside the TextButton)

local TextButton = script.Parent --Gets the button that its going to be touched
local ImageLabel = TextButton.Parent.ImageLabel --Basically your "menu" variable


local debounce = false --Information so the scripts knows if it has been activated before

TextButton.Activated:Connect(function() --When the button is Activated then Connect the action to a new function
	if not debounce then --Checks if it has activated before, if not then do the next code
		debounce = true --Set the information to true, so the next time it is activated the image wont show
		ImageLabel.Visible = true --dont have to explain this
		print("Image showed") --neither
	else --this says "if debounce is true (if the button has been activated before) then do this"
		debounce = false --set the information back to false so the next time the button is activated is going to repeat
		ImageLabel.Visible = false --bruh
		print("Image Removed") -- :/
	end
end) --this last ")" its because it was ( function(here it goes a parameter) and the close ")" goes here at the end
1 Like

It’s still not working. It won’t show any errors, but the print messages aren’t showing up. The only thing I can think of is that I have a script constantly running in the background, but I don’t know why that would mess it up because it has an hour long wait time in between each time it runs.

is the script that is running in the background in the same as where the TextButton script is?

cause if it is and as you say it has an hour wait then it wont run, you could try doing a coroutine and paste there your code that is running in the background

You should read this for more information for coroutines since im not an expert but basically it lets you run a code in the background while still running the code, imagine it like a road that has two sides, if one side is blocked, you can still go by the other side of the street

1 Like

No. It is not in the same place. Should I still use coroutines?

You mean like not in the same script, right?

Yes. It is a completely different script in server script service.

k, then dont use coroutines, can i see the code that you have now? just to see if i there’s any errors

I did what you told me to and cut it down to one script. Here it is:

local menuButton = script.Parent
local menu = game.StarterGui.MenuGUI.Menu

local menuOpen = false

local function openOrCloseMenu ()
	if not menuOpen then
		menuOpen = true
		menu.Visible = true
		print("Image Shown")
	else
		menuOpen = false
		menu.Visible = false
		print("Image Closed")
	end
end

menuButton.Activated:Connect openOrCloseMenu()

Sorry, it is showing the print messages now, but it won’t turn the menu visible.

Is this for the whole server to see or just the player?

It is for just the player. It is inside Starter GUI.

Players have their own GUI, which is located in the Players Service

However you can locate their gui like this.

game.Players.LocalPlayer:FindFirstChild("PlayerGui") -- direct its path to the gui.
1 Like

That worsened the problem. The current problem is that the GUI isn’t becoming visible when I click the button. Here is the script:

local menuButton = script.Parent
local menu = game.StarterGui.MenuGUI.Menu

local menuOpen = false

local function openOrCloseMenu ()
	if not menuOpen then
		menuOpen = true
		menu.Visible = true
		print("Image Shown")
	else
		menuOpen = false
		menu.Visible = false
		print("Image Closed")
	end
end

menuButton.Activated:Connect(openOrCloseMenu)

Oh, if ur doing that to a gui do menu.Enabled = (false or true).
If its a frame or etc they use Visible :slight_smile:

Ok, i see the problem here, just change game.StarterGui.MenuGUI.Menu, this line is looking what its in the starter gui, but when you start the game, everything on the starter gui moves to the player gui, so its basically looking in a empty folder, in order to work it should be something like

local menu = menuButton.Parent.Menu

(I tried this change with your script and it worked perfectly)

robloxapp-20220221-1601114.wmv (177.3 KB)

because since the button is inside the starter gui it will be moved to the starter gui with everything that was in there, in order to change gui is always better to use parents and childs

2 Likes

You shouldnt be calling the StarterGui.

Get the PlayerGui as the GUI in StarterGui Clones and Parents to PlayerGui when youre loaded in.

Need more info on what PlayerGui is? Click Here to view DevHub Article

Here’s a screenshot of my situation:
Screenshot 2022-02-21 141836
What should I do in this case? I tried this:

local gameMenu = menuButton.Parent
local gameMenuGui = gameMenu.Parent
local StarterGUI = gameMenuGui.Parent
local menuGui = StarterGUI.MenuGUI
local menu = menuGui.Menu

It still didn’t work, so what should I do in this case?

then you could try to use the player gui, but instead of locating them like you normally will do with any other folder you must do local menuGui = PlayerGui:WaitForChild("MenuGUI"), cause the script runs even before things in the starterGui are send to the playerGui, so if you do local menuGui = PlayerGui.MenuGui it will print an error, WaitForChild waits until MenuGui appears where you are looking (You can also do local example = workspace:WaitForChild("Example", 3) if you want to put how much time it is waiting for the part to appear, in this case if it can’t locate “Example” after 3 seconds, it will continue to run and left the var = nil)

1 Like