UI - TextButton script not working

Hey! I was making some UI stuff for my game, and I wanted to make a text button, and when the textbutton is clicked, make visible a frame and then clicking again, make invisible back again the frame.
I wrote one code but isn’t working, here it is:

local button = script.Parent.TextButton 
local frame = script.Parent.Frame 
local function toggleFrame() 
    if frame.Visible == true then 
        frame.Visible = false 
    else 
        frame.Visible = true 
    end
end
button.MouseButton1Click:Connect(toggleFrame)

It would be really helpful if someone can re-make my code if there are any issues with it or make a new one and reply here, thanks!

1 Like

Where is the script located at?

Is there an error on output???

The script seems to look very fine, look at the Hierachy and check if its correct

Ill just tell you this right now

  1. You need to change the playergui, not the one in starter gui
  2. You might have referenced something wrong

Is it a LocalScript? If not, make it a LocalScript instead of a regular Script. And like @yoshicoolTV said:

Inside the textbutton, on the frame inside the UI.

No, it doesn’t appears any error or warning output on the game console.

Can you show a picture of it (from the explorer) if you don’t mind

Yeah, no problem! Here it is:
Captura de pantalla 2023-09-08 a las 18.29.25
shop & update buttons are the ones that I want to make for make visible or invisible frames (different options on the menu)

I would suggest parenting the Local Script in an Instance where it can run. For example, the ScreenGui you created. You can parent it there.

Uhm, looking at your script you have to define what exactly you want to change like

local button = script.Parent.TextButton

Doesn’t exist, there is only play, shop and updates (according to your naming of the TextButton). You have to exactly pin point what text button it is, same thing goes for

local frame = script.Parent.Frame

I am not really sure if you the Child of ScreenGui or the other two, but yeah

Also I don’t see a localscript in here, is the script in a TextButton or Frame? (you should also maybe show where the local script is)

Hey! So the UI is located there as it is a baseplate for only the game main menu, as there are many options such as buy on the shop, check lastest updates, or just be teleported to game.

Hey! So I made changes on script following suggestions from some answers, here is how script looks like & explorer too:

local button = game.StarterGui.ScreenGui.Frame.shop
local frame = script.Parent.Frame.Tienda
local function toggleFrame() 
	if frame.Visible == true then 
		frame.Visible = false 
	else 
		frame.Visible = true 
	end
end
button.MouseButton1Click:Connect(toggleFrame)

Explorer screenshot:
Captura de pantalla 2023-09-08 a las 18.56.49
Here “Local Script” it’s actually where’s located at the script inside the screen gui, and then the frame that I need to code for the button is shop. It’s still not working so i’ll really appreciate any help.

Now knowing what you want to change: Here this will work! (i hope)

local button = script.Parent.Frame.shop
local frame = script.Parent.Frame.Tienda
local function toggleFrame() 
	if frame.Visible == true then 
		frame.Visible = false 
	else 
		frame.Visible = true 
	end
end
button.MouseButton1Click:Connect(toggleFrame)

Thank you for the help, it’s now working, I really appreciate tysm!!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.