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.

script.Parent.MouseButton1Down:connect(function()
    local text = script.Parent.Parent.Parent.npcChat.ImageLabel.TextLabel.Text
    local txtTable = {
        "t",
        "e",
        "s",
        "t",       
    }
    text = table.concat(txtTable, ' ')
end)

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

function characterChatspellOut(text)
    local textlen = string.len(text)
    for i = 1, textlen do
        print(string.sub(text, 1, i))
        if textlen >= 20 then
            wait(0.04)
        elseif textlen >= 15 then
            wait(0.05)
        elseif textlen >= 10 then
            wait(0.07)
        else
            wait(.1)
        end
    end
end

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

Base script

function characterChatspellOut(text)
    local textlen = string.len(text)
    for i = 1, textlen do
        print(string.sub(text, 1, i))
        wait(0.05)
    end
end

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