I made a way to make NPC type that actually works, but to make it talk, I paste it as much times as the number of characters in the sentence, and then make it so after 0.05 seconds it types another character. Is there a faster way instead of removing a character from the text every time? (This is a LocalScript, so it can work with filteringenabled.)
function onClick3(plr) local text = plr.PlayerGui.TalkGui.Message3.TextLabel text.Parent:TweenPosition(UDim2.new(0.3,0, 0.623,0),'Out', 'Quad', 0.23) -- gui pops up wait(0.25) sound:Play() -- talking sound plays text.Text = "" wait(0.05) text.Text = "D" wait(0.05) text.Text = "Do " wait(0.05) text.Text = "Do y" wait(0.05) text.Text = "Do yo" wait(0.05) text.Text = "Do you " wait(0.05) text.Text = "Do you l" wait(0.05) text.Text = "Do you li" wait(0.05) text.Text = "Do you lik" wait(0.05) text.Text = "Do you like " wait(0.05) text.Text = "Do you like b" wait(0.05) text.Text = "Do you like be" wait(0.05) text.Text = "Do you like bei?" wait(0.05) text.Text = "Do you like bein" wait(0.05) text.Text = "Do you like being " wait(0.05) text.Text = "Do you like being c" wait(0.05) text.Text = "Do you like being cl" wait(0.05) text.Text = "Do you like being cla" wait(0.05) text.Text = "Do you like being clas" wait(0.05) text.Text = "Do you like being class" wait(0.05) text.Text = "Do you like being classy" wait(0.05) text.Text = "Do you like being classy?" sound:Stop() wait(0.1) text.Parent.Buttons.Visible = true -- answer buttons pop up end workspace.Classynoob_lol.Torso.Click.MouseClick:Connect(onClick3) --connection
string.sub
is what you'll need. string.sub(text, start, end)
will return the part of the string from the start
to end
, or from the start
to the end of the string - if the end
parameter isn't specified.
local txt = 'Do you like being classy?' for i = 1, #txt do text.Text = txt:sub(1, i) wait() end
P.S: txt:sub(1, i) is syntactic sugar for string.sub(txt, 1, i)