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

How to make this easier or simpler?

Asked by 10 years ago

I was making a script that will display a sentence letter by letter but then I figured that there could be something easier to do this. Is there any easier or simpler way?

        script.Parent.Parent.Story.Text="O"
        wait(0.15)
        script.Parent.Parent.Story.Text="On"
        wait(0.15)
        script.Parent.Parent.Story.Text="One"
        wait(0.15)
        script.Parent.Parent.Story.Text="One n"
        wait(0.15)
        script.Parent.Parent.Story.Text="One ni"
        wait(0.15)
        script.Parent.Parent.Story.Text="One nig"
        wait(0.15)
        script.Parent.Parent.Story.Text="One nigh"
        wait(0.15)
        script.Parent.Parent.Story.Text="One night"
        wait(0.15)
end)
0
there is an easier way, give me a sec to write out NinjoOnline 1146 — 10y

2 answers

Log in to vote
1
Answered by
Nifer2 174
10 years ago
local string = "One night"

for i=1, string:len() do
    script.Parent.Parent.Story.Text = string:sub(1, i)
    wait(0.15)
end

string:len() finds the length of the string. The script loops until it has spelled out the entire string.

Ad
Log in to vote
1
Answered by
Muoshuu 580 Moderation Voter
10 years ago
local Text="One night"

for i=1,#Text do
    script.Parent.Parent.Story.Text=Text:sub(1,i)
    wait(.15)
end
0
On line 4, you have an extra parenthesis. Nifer2 174 — 10y
0
Oh oops, I edited it because before it said 'print(Text:sub(1,i))' Muoshuu 580 — 10y

Answer this question