ObjectValue keeps indexing nil with 'TextLabel'

This script finds an ObjectValue and this line should set the value as the text, but wont work.

script.Parent.Name.SurfaceGui.TextLabel.Text = game.Workspace.Items.EOD.Value.Name

Ive tried many things, and I understand how ObjectValues work, but cant get this to work…

It keeps returning nil with TextLabel. I assume its because of the ObjectValue.

maybe try removing the name after the .Value? i dont know im not smart

also is EOD a object value?

Yes, and I did try removing Name but it shows the same error.

oh well then my tiny peanut brain has no ideas

script.Parent.Name.SurfaceGui...
Is Name a child of script.Parent? Or a property?

Even if it is a child, i think the problem is because you are not waiting for the things such as the SurfaceGui or the TextLabel to show up. Here is how you should reach the TextLabel/EOD:

local Main = script.Parent
local NameGui = Main:WaitForChild("Name")
local SurfaceGui = NameGui:WaitForChild("SurfaceGui")
local TextLabel = SurfaceGui:WaitForChild("TextLabel")

local ItemsFolder = workspace:WaitForChild("Items")
local EOD = ItemsFolder:WaitForChild("EOD")

TextLabel.Text = EOD.Value.Name

The WaitForChild function will wait for an object with the name given to appear, since when your game first starts most instances haven’t yet been created (Like the Baseplate).

1 Like

Thanks. That works. :slight_smile:

Ill try edit the original slightly and include :WaitForChild’s

Edit:
Seems like only your method will work. Which is a shame, but atleast there is a solution. :slight_smile: