Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I reference an item when it is in multiple parents?

I didn't know what to name the title but basically here is my code and I want to reference a text label but it's on StarterGui, MenuGui, Frame, Text Button. Here is my code.

local textButton = script.Parent
local textLabel = game.Workspace.StarterGui.MenuGui.Frame.TextButton.textLabel
textButton.MouseButton1Click:Connect(function()
	textLabel.Visible = true
end)

1 comment

0

Technically speaking, it doesn't have multiple parents. It has multiple ancestors.

1 answer

A couple of things to list right off the bat:

1. StarterGui is a service and not a member of game.Workspace

2. The version of the ScreenGui that you are referencing in StarterGui will not be changed. No players have direct access to the version in StarterGui. The correct method would be accessing the GUI from the Player's PlayerGui folder (a child of the Player instance in "Players" service)

LocalScript:

local textButton = script.Parent
local Player = game:GetService("Players").LocalPlayer
local textLabel = Player.PlayerGui.MenuGui.Frame.TextButton.textLabel 
-- If textLabel is a child of the textButton variable, you could also do
-- local textLabel = textButton:WaitForChild("textLabel")
textButton.MouseButton1Click:Connect(function()
    textLabel.Visible = true
end)

I would also recommend doing checks to make sure each element you are referencing actually exists to prevent nil errors.

6 comments

0

Thank You

0

Wait it still didn't work.

1

Do you get any errors?

0

No.

1

When you hover over the button, does its background change colors automatically? If not, I would suggest increasing the TextButton's Z-index

0

Can anyone help me.

This discussion is preserved as it was. New answers, comments, and votes are closed.