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

Quicker way for NPC type?

Asked by 6 years ago

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

0
I give you a challenge: Make a function that accepts an argument that is any string, The function will take the string and display each character one by one, based on how long it is and how much type you make it delay. This could be fun! :D Pojoto 329 — 6y

2 answers

Log in to vote
1
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

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)

Ad
Log in to vote
-1
Answered by 6 years ago

You can't do it :(

Answer this question