UI Within UI Issue (About Sword Info)

Hello! I’m typing this because there is currently an issue with my game involving a small button inside of a menu that is also inside of another menu. This button is supposed to bring up another menu detailing info. I have the frame and text button looking pretty fresh, but when I try to make the frame appear from the button with a LocalScript, it doesn’t seem to work at all. Here is the hierarchy picture and code. The button is labeled Info and the frame is simply called frame.
image
local button = script.Parent
local frame = script.Parent.Parent:WaitForChild(“Frame”)
local debounce = false
button.MouseButton1Up:Connect(function()
if debounce == false then
debounce = true
frame.Visible = true
elseif debounce == true then
debounce = false
frame.Visible = false
end
end)

1 Like

I noticed, while putting this line into a local script,

local frame = script.Parent.Parent:WaitForChild(“Frame”)

The (‘‘frame’’) was marked as an error.

It was due to the quotes, so I rewrote the quotes, and it worked fine:

local frame = script.Parent.Parent:WaitForChild("Frame")

1 Like

It didn’t fix it. I think the quotes was just the dev forum.

the problem is how you’re getting the parents
if the button is script.Parent then the Frame is script.Parent.Parent.Parent.Frame (button.Parent.Parent.Frame)

if you want to toggle visibility then check if the frame is visible or not; not if a variable (debounce) is true or false

local debounce = false -- Improper use of 'debounce'
local Info = script.Parent
-- Info.Parent is SwordMenu, SwordMenu.Parent is StuffMenu
local Frame = Info.Parent.Parent:WaitForChild("Frame")

Info.MouseButton1Click:Connect(function()
  if Frame.Visible then
    Frame.Visible = false
  else
    Frame.Visible = true
  end
end)

i would do it like this instead of worrying about '.Parent’s

-- If I'm modifying an object that's outside of the button, I'd move the script to the object's parent
local StuffMenu = script.Parent 

local Frame = StuffMenu:WaitForChild("Frame")
local InfoButton = StuffMenu:WaitForChild("SwordMenu"):WaitForChild("Info")

InfoButton.MouseButton1Click:Connect(function()
  -- I'd just do a one-liner
  Frame.Visible = not Frame.Visible
end)
1 Like

Thanks for letting me know my mistake! However, I’ve tried the new script out in Sword Menu and it doesn’t seem to work.

you’re using a local script right?

also i wrote 2 ways you could do it which depends on where you put the scripts

Yeah, a local script is 100% what I’m using. Should I switch to a regular script?

yes it should be a local script

what did you put in your script and where did you put it

I put the script in the Sword Menu and wrote
local StuffMenu = script.Parent

local Frame = StuffMenu:WaitForChild(“Frame”)
local InfoButton = StuffMenu:WaitForChild(“SwordMenu”):WaitForChild(“Info”)

InfoButton.MouseButton1Click:Connect(function()
Frame.Visible = not Frame.Visible
end)

if you read the comment i made

-- If I'm modifying an object that's outside of the button, I'd move the script to the object's parent

i was saying: since the frame is being modified, the script and the frame should have the same parent

OHHHHHH I get it now, I’ll test it out again

So it still doesn’t work. I’ll give you the rundown. I really hope I’m not pissing you off with all this because I feel like I’m just being a chore to deal with at this point.
image

move the script into StuffMenu so Frame and the LocalScript can have the same parent

if you move the Frame into SwordMenu (which is what you did) then you’ll need to update the script
what you just did doesn’t match the script

local StuffMenu = script.Parent -- StuffMenu should be the Parent not the SwordMenu

Ok, I put the script into the stuff menu and yet still it doesn’t work. I have no idea what is going on with it.

i’m assuming you didn’t move the frame back to the stuffmenu

I am so embarrassed right now. You were 100% correct. You can tell UI scripting is something I can’t get behind. I am sorry for wasting your time if I did.

it seems like you just need to learn what children and parents are

image

here’s an example
image

  • Everything has 1 parent

  • Frame has 2 children (TextButton, TextButton)

  • ImageLabel has no children

  • ScreenGui has 2 children (Frame, ImageLabel) and 4 descendants (Frame, TextButton, TextButton, ImageLabel)

TextButton’s Parent is Frame
ImageLabel’s Parent is ScreenGui

if i had a script and its parent is ScreenGui then it would look like this
image

LocalScript’s parent is ScreenGui

local ScreenGui = script.Parent -- The script's Parent is ScreenGui
local Frame = ScreenGui.Frame -- Frame is ScreenGui's child
local TextButton = Frame.TextButton -- TextButton is Frame's child

local TextButton = ScreenGui.Frame.TextButton 
-- TextButton is Frame's child, and Frame is ScreenGui's Child
-- TextButton is ScreenGui's descendant

print(TextButton.Parent.Parent) --> ScreenGui
-- TextButton's Parent is Frame, and Frame's Parent is ScreenGui
-- ScreenGui is TextButton's anscestor

now if you read my script

local StuffMenu = script.Parent -- StuffMenu is LocalScript's parent

local Frame = StuffMenu:WaitForChild("Frame") -- Frame is StuffMenu's child
local InfoButton = StuffMenu:WaitForChild("SwordMenu"):WaitForChild("Info") 
-- Info is SwordMenu's Child, and SwordMenu is StuffMenu's child
-- Info is StuffMenu's descendant

-- MouseButton1Click isn't a child but it has a connection; MouseButton1Click must be a event
InfoButton.MouseButton1Click:Connect(function()
  -- Visible isn't a child but its being modified; Visible must be a property 
  Frame.Visible = not Frame.Visible
end)

image

1 Like

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