you currently cannot do it with a single TextLabel
, you’d need another separate for the word land
the easiest method to do it is with TextService:GetTextSize()
, you can look it up here:
https://developer.roblox.com/en-us/api-reference/function/TextService/GetTextSize
i’ve worked on this a while back, you can check out my module here:
local text = {}
local ttt = false
local player = game.Players.LocalPlayer
local ts = game:GetService("TextService")
local ss,ssb,ssi,sssb = Enum.Font.SourceSans,Enum.Font.SourceSansBold,Enum.Font.SourceSansItalic,Enum.Font.SourceSansSemibold
function text:newtext(str)
wait()
if ttt == true then player.PlayerGui.Text:Destroy() ttt = false end
ttt = true
--Turning the string into a list
local function list(s)
local t = {}
local h = string.gsub(s,"<.-/.->",function (w) return "|"..w.."|" end ) h = "|"..h.."|"
for word in string.gmatch(h,"([^|]*)") do if word ~= "" then table.insert(t,#t+1,word) end end
return t
end
local t = list(str)
------------------------
local z = {} --Turning list into detailed list
for k,v in pairs(t) do
local f = string.match(v,"<(%P-)>") or "n"
local r = string.match(v,">(.-)<") or v
local a = {r,f}
if f == "n" then table.insert(a,3,ss)
elseif f == "b" then table.insert(a,3,ssb)
elseif f == "i" then table.insert(a,3,ssi)
elseif f:sub(1,6) == "color " then table.insert(a,3,sssb)
end
table.insert(z,k,a)
end
--Setup for the text
local GUI = Instance.new("ScreenGui",player.PlayerGui)
GUI.Name = "Text"
local x,y = 0,0
for k,v in pairs(z) do
local s = ts:GetTextSize(v[1],28,v[3],Vector2.new(math.huge,math.huge))
table.insert(v,4,x) table.insert(v,5,s.X)
if k == 1 then y = s.Y end
x = x + s.X
end
local frame = Instance.new("Frame",GUI)
frame.BackgroundTransparency = 1
frame.BorderSizePixel = 0
frame.ClipsDescendants = false
frame.Size = UDim2.new(0,x,0,y)
frame.Position = UDim2.new(.5,-x/2,.8,-y/2)
for k,v in pairs(z) do
local TextLabel = Instance.new("TextLabel",frame)
TextLabel.TextSize = 28
TextLabel.BackgroundTransparency = 1
TextLabel.BorderSizePixel = 0
TextLabel.Name = k
TextLabel.TextStrokeTransparency = 0
TextLabel.TextStrokeColor3 = Color3.new()
TextLabel.Text = ""
TextLabel.TextXAlignment = Enum.TextXAlignment.Left
TextLabel.Font = v[3]
TextLabel.Size = UDim2.new(0,v[5],0,TextLabel.TextSize)
TextLabel.Position = UDim2.new(0,v[4],0,0)
if v[2]:sub(1,6) == "color " then
local c1,c2,c3 = tonumber("0x"..v[2]:sub(7,8)),tonumber("0x"..v[2]:sub(9,10)),tonumber("0x"..v[2]:sub(11,12))
TextLabel.TextColor3 = Color3.fromRGB(c1,c2,c3)
else
TextLabel.TextColor3 = Color3.new(1,1,1)
end
table.insert(v,6,TextLabel)
end
--Text appearing
local len = str:len()
for k,v in pairs(z) do
local TextLabel = v[6]
for i = 1,v[1]:len() do
TextLabel.Text = v[1]:sub(1,i)
if v[1]:sub(i,i) == "." then wait(.4) elseif v[1]:sub(i,i) == "," then wait(.2) else wait() end
end
end
end
function text:close()
if ttt == true then player.PlayerGui.Text:Destroy() ttt = false end
end
return text
there’s not much context but hopefully it’ll give you a bit of insight(maybe?)
i just tested it and it still works, just require it with a LocalScript
and run Module:newtext(str)