Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I create textLabel through code?

Asked by 4 years ago

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?

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 bum5Br 97 — 4y
0
Don't parent it in the same line you create it, parent it in a different line: label.Parent = ScreenGui Rinextel 291 — 4y
0
Line 5, it's not Color3.new, it's Color3.fromRGB(0,0,0). And line 3, remove the curly brackets. Rinextel 291 — 4y
0
u forgot to set the label position :/ XD TNTIsLyfe 152 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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}
1
good job! royaltoe 5144 — 4y
0
thx SoftlockedUnderZero 668 — 4y
Ad

Answer this question