Why is the text label not appearing in the list?

Greetings,

I made a list and the code was supposed to create a text label with the settings I written it. For some reason, there are no errors and the label does not appear in any way. Any ideas? Code and placement down below:

local Text = Instance.new(TextLabel, script.Parent)

Text.BackgroundTransparency = 1
Text.TextColor3 = Color3.new(1, 1, 1)
Text.Font = Enum.Font.Sarpanch
Text.TextScaled = true
Text.Text = "Quantity: " ..MaterialOrder.Value.." | Price: "..MaterialOrder.Value * 0.24 .." $"

Screenshot 2022-08-08 160828

1 Like

its a bad practice to put assign the Instance’s Parent next to the instance creation itself
a better way to do this :

local Text = Instance.new(TextLabel)
Text.Parent = script.Parent

It isn’t showing probably because you are setting the text color to white on a white background.

Umm… no? There is no white background or anything in my game. And I think I did BackgroundTransparency to 1 so yea…

Is the OrderList frame background color set to white? Also Color3.new(1,1,1) returns white.

You need to check both starterGUI and playerGUI

This is the thing. the gray shape is the order list (where the product should’ve gotten listed) . As you can see there are no such white backgrounds. And yes ik, I wanted the writing to be white.

Screenshot 2022-08-08 162152

Your frame could be overlapping with the textlabel.

Hold up everyone, I think I found the problem? I think it’s the size of the label. The label itself appears in the folder and everything seems to be alright, but the size is 0 0 on all of them.

I thought that it would receive the default label size as when you insert it in a frame?

Can anyone tell me please how to change the size of the text label through script?

Screenshot 2022-08-08 163458

I tried doing it, but I get this error.

You need to assign the size property with a UDim2. like TextLabel.Size = UDim2.fromScale(.25, .25).

1 Like

Hello there,


Just a helpful and handy tip, do not ever use the second parameter of the Instance.new constructor function. (It is a really bad practice, and IIRC, it performs slower than doing it manually.)

Instead, what you want to do is set the parent of the instance like this:

local Text = Instance.new("TextLabel")
Text.Parent = script.Parent

Overall, this is much better and should be practiced more often. And also, do not parent it before applying the instance’s properties.

-- **DON'T DO **
local Text = Instance.new("TextLabel")
Text.Parent = script.Parent
Text.Font = Enum.Font.GothamBold

-- ** DO **
local Text = Instance.new("TextLabel")
Text.Font = Enum.Font.GothamBold
Text.Parent = script.Parent

Now, for your issue/problem. Everything seems to be right as intended except for the Size property of the label. Now, IIRC (again), when creating a new TextLabel instance, there will be no default Size value provided, therefore you must do/set it on your own which in this case you haven’t.

Yes, there is a Size property for GuiObject. You could either set it manually via Studio explorer or through a script like so:

TextLabel.Size = UDim2.new(1, 0, 1, 0)
-- (X | scale, offset, Y | scale, offset)

If I may insist, you could try this code that I have rewrote from the original code that you provided on the original post:

local list = script.Parent :: Frame
-- Let's assume that the `OrderList` in the picture
-- from the post is a Frame.

local text = Instance.new("TextLabel")
text.Size = UDim2.new(1, 0, 0.175, 0)
text.BackgroundTransparency = 1
text.TextColor3 = Color3.fromRGB(0, 0, 0)

text.Font = Enum.Font.Sarpanch
text.TextScaled = true
text.Text = "Quantity: " .. MaterialOrder.Value .. " | Price: " .. MaterialOrder.Value * 0.24 .. "$"

text.Parent = list
-- We are parenting the `TextLabel` to the list.
1 Like

Well, that works. Everything works as intended now. Thanks.

I guess the problem was the sizing.

I don’t quite get it at the font and parent (at the don’t do and do). What does it affect?

Anyways, good to keep in mind the tips I see in your answer, thank you too!

Setting the parent last is better for performance. Roblox recommends setting the parent last as outlined in the Instance docs.
See this thread if you want to know more.