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

How do I create textLabel through code?

As the title of my question indicates, I am looking at creating a label for a player Gui in Roblox using only code. Under the folder StarterGui, I have a ScreenGui, and as a child of ScreenGui I have a local script with the following code:

local ScreenGui = script.Parent
local label = Instance.new("TextLabel", ScreenGui)
label.Size = UDim2.new({0, 200},{0, 100})
label.Text = "label"
label.TextColor3 = Color3.new (0,0,0)
label.TextSize = 36
label.Font =  "Arial"
label.TextScaled = true

I am pretty sure I should be seeing a label with the word ''label'' by now, but nothing. What am I missing?

4 comments

0

I don't wanna make an Answer because i'm not quite sure either, but i don't think you can create Instances using a local script, try using a normal script

0

Don't parent it in the same line you create it, parent it in a different line: label.Parent = ScreenGui

0

Line 5, it's not Color3.new, it's Color3.fromRGB(0,0,0). And line 3, remove the curly brackets.

0

u forgot to set the label position :/ XD

1 answer

✓ Accepted answer

Line 3, Remove the curly brackets. For some reason putting in the UDim2.new function returns with 0,0,0,0. Here's a comparison:

print( UDim2.new(0, 200,0, 50) ) --> {0, 200}, {0, 50}
print( UDim2.new({0, 200},{0, 50})) --> {0, 0}, {0, 0}

2 comments

1

good job!

0

thx

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