I wanna achieve a type of animal crossing talking GUI using the talking function that I have. Nico (the guy who made nicos nextbots) made a system like it and I wanna kind of make it like that. (video below)
I tried making it myself but it didn’t work out since I’m not at that skill level yet.
local function typetalkwriter(object, text)
for i = 1, #text do
talkindication.Visible = true
soundtalk:Play()
object.Text = string.sub(text, 1, i)
wait(talkspeed)
talkindication.Visible = false
end
end
You don’t have to write it for me if you don’t want to. I mostly just need the stuff I need to actually make it.
You should be using TextLabel.MaxVisibleGraphemes instead of constantly changing the text. That new property is specifically designed for a typewriter effect. Essentially, it is a number that tells the TextLabel how many characters from .Text to show.
There is also the .ContentText property, which will show you what is being displayed to the player.
Below is an example function with a debounce check. To prevent yielding, it should be called with task.spawn
local function typewriter(obj: TextLabel, text: string)
if obj:GetAttribute('IsTypewriting') then return end --debounce check
obj:SetAttribute('IsTypewriting', true)
obj.MaxVisibleGraphemes = 0 --make the text invisible first
obj.Text = text
local len: number = #text
local counter: number = 0
while counter < len do --will iterate until it reaches the end of the string
counter += 1
obj.MaxVisibleGraphemes = counter
task.wait() --increment every frame
end
obj.MaxVisibleGraphemes = -1 --negative 1 means show everything
obj:SetAttribute('IsTypewriting', false)
end
local label = script.Parent
--the while-loop inside the function would cause the thread to yield
--using a coroutine prevents this
task.spawn(typewriter, label, 'Can we get much higher')
Well then you’re gonna have to use string.sub again lol
The counter variable tells you the current length of the text and you can use that to figure out the letter that was just added
while counter < len do
counter += 1
obj.MaxVisibleGraphemes = counter
local letter: string = string.sub(text, counter, counter)
--do something with the letter, for example if you have a lookup table of sounds:
local sound = letterSounds[letter]:Play()
task.wait()
end
i am not really that good with tables could you help me with making it too? sorry if im asking you for too much but if you dont wanna i could just try to figure it out myself.
like the timing part of it i mean ofc i can make a basic table but im a little bit of a beginner when it comes to luau but im learning from all the help!
nevermind figured it out on my own heres the code if anyone needs it!
local talkspeed = 0.025
local letterSounds = {script.a,script.b,script.c,script.d,script.e,script.f,script.g,script.h,script.i,script.j,script.k,script.l,script.m,script.n,script.o,script.p,script.q,script.r,script.s,script.t,script.u,script.v,script.w,script.x,script.y,script.z}
local function typewriter(obj: TextLabel, text: string)
if obj:GetAttribute('IsTypewriting') then return end --debounce check
obj:SetAttribute('IsTypewriting', true)
obj.MaxVisibleGraphemes = 0 --make the text invisible first
obj.Text = text
local len: number = #text
local counter: number = 0
while counter < len do
counter += 1
obj.MaxVisibleGraphemes = counter
local letter: string = string.sub(text, counter, counter)
if letter == " " then
letter = "`"
end
print(letter)
print(letterSounds)
--do something with the letter, for example if you have a lookup table of sounds:
local sound = script[letter]:Play()
wait(talkspeed)
end
obj.MaxVisibleGraphemes = -1 --negative 1 means show everything
obj:SetAttribute('IsTypewriting', false)
end
local label = script.Parent
task.spawn(typewriter, label, 'banana')