Splitting the Username/Display Name string

Hello Everyone! I need help with this typewriter effect where I split the string of a username/display name
My Current Code (very aware this doesnt work, from an old project):

for i = 1,string.len("Display Name:") do
		local letterofPlrDisplayName = string.sub(game.Players.LocalPlayer.DisplayName,i)
		table.insert(displayNameSplit1,letterofPlrDisplayName)
	end


it produces this…not what i want
Help appreciated, thank you!

Just wondering if this is in a textbox, label, or button. If it is, then you can use the texttruncate property

its a label. never used this TextTruncate thing before, how does it work?

If i’m correct, you can just set the text of the textlabel to whatever you want, and then do a script sort of like this:

local label = --your textLabel
local name = --player name or whatever text

for index = 1, string.len(textLabel) do
      label.textTruncate += 1
      task.wait(0.1) --effect time
end

Sorry if this has errors; I was making it pretty fast. Hopefully this should give you a basis.

For textTruncate, it should just completely cut off your text at the provided index

Edit: NOT textTruncate, the correct property is MaxVisibleGraphenes

I’ve created the effect in studio with this script:

local player = game.Players.LocalPlayer
local label = script.Parent.TextLabel

label.Text = player.Name

task.wait(5)
for index = 1, string.len(player.Name) do
	label.MaxVisibleGraphemes += 1
	task.wait(0.05)
end

Just so you know, the textLabel already has MaxVisibleGraphemes set to 0 and this is a LocalScript inside of the screenGui containing the textLabel in question.

Seem to be having issues

displayname.Text = displayname.Text.." "..game.Players.LocalPlayer.DisplayName -- by default displayname is "Display Name:"
for i=1, (string.len(game.Players.LocalPlayer.DisplayName) + string.len("Display Name:")) do
		displayname.MaxVisibleGraphemes += 1
		task.wait(0.1)
	end

image
results:
edit: yes, the max visible graphemes is set to 0

The issue is likely arising because of the gap between display name and the actual display name
image
It looks to be about 2 spaces long, which is the same number of characters that the typewriter is off by.

Try this code instead:

displayname.Text = "Display Name: " ..game.Players.LocalPlayer.DisplayName -- by default displayname is "Display Name:"
for i=1, #displayname.Text do
	displayname.MaxVisibleGraphemes = i
	task.wait(0.1)
end

It’s very similar to what Mr_Spokes has been doing, but just written slightly differently to prevent issues.

local text = "Display Name: "..game.Players.LocalPlayer.DisplayName
local current = ""
for i = 1, text:len() do
	local letter = text:sub(i, i)
	current ..= letter 
	print(current)
	task.wait(1)
end

Is that what you’re trying to do?

Seems to work, I guess i just added an extra space or something?

Yeah, I think you added an additional space ontop of one that was already in the textbox, without accounting for either in the code.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.