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

"Typing" UI scheme? (Need help, should be simple)

Asked by 9 years ago

For example, someone typing a sentence using a Keyboard. I'm trying to mimic that but I've never done it before, this is my best guess.

Also, to put it in perspective, think about an RPG and when the NPC's talk to you.

This script is for an NPC GUI. When you press a "Chat" button it will greet you with the following script using a 'typing' scheme.

01script.Parent.MouseButton1Down:connect(function()
02    local text = script.Parent.Parent.Parent.npcChat.ImageLabel.TextLabel.Text
03    local txtTable = {
04        "t",
05        "e",
06        "s",
07        "t",      
08    }
09    text = table.concat(txtTable, ' ')
10end)

1 answer

Log in to vote
1
Answered by 9 years ago

Do you mean something like instead of the text appearing all at once it appears by each individual letter? Lucky for you, I think I made that script a long time ago and still have it. Tadaa

01function characterChatspellOut(text)
02    local textlen = string.len(text)
03    for i = 1, textlen do
04        print(string.sub(text, 1, i))
05        if textlen >= 20 then
06            wait(0.04)
07        elseif textlen >= 15 then
08            wait(0.05)
09        elseif textlen >= 10 then
10            wait(0.07)
11        else
12            wait(.1)
13        end
14    end
15end

I'm going to explain it a little just in case you are curious.

Base script

1function characterChatspellOut(text)
2    local textlen = string.len(text)
3    for i = 1, textlen do
4        print(string.sub(text, 1, i))
5        wait(0.05)
6    end
7end

The different between the script above and the first one is that sometimes when I have really long dialogue I prefer to speed it up. To do this, in the first script I say if the text length(textlen) is greater then 20 characters then(and then I make the wait smaller) Hope this helps.

Ad

Answer this question