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

Issue With Typewriter Script, Cuts off At a Point. What's wrong?

Asked by 4 years ago

Basically, I'm trying to make it so it appears text after another. Everything works fine on that aspect, but when it reaches the point where text3 is being written, it cuts of before it finishes. The point where it exactly cuts of is right after 'here' in the variable.

I have no idea why it's not working, and I've tried changing it, but it still didn't work. I'm probably stupid, but whatever. If anyone knows what's wrong, please let me know. Thanks!

(Also, everything else works, only that part of the script)

local text = "why are you still here"
local text2 = "im talking to you, bud"
local text3 = "why have you been here for like 6 minutes?"
local text4 = "ok so you just going to sit here?"
local text5 = "okay lets go to an obby"

local option1 = game.StarterGui.ScreenGui.Frame.option1
local option2 = game.StarterGui.ScreenGui.Frame.option2



game.ReplicatedStorage.Remotes.Gui3.OnClientEvent:Connect(function()

wait(5)

for i = 1, #text do
    script.Parent.Text = (string.sub(text, 1, i))
    wait(0.07) --This is the speed of the text
end

wait(3)

for i = 1, #text do
    script.Parent.Text = string.sub(text2, 1, i)
    wait(0.07) --This is the speed of the text
end

wait(5)

for i = 1, #text do
    script.Parent.Text = string.sub(text3, 1, i)
    wait() --This is the speed of the text
end

for i = 1, #text do
    script.Parent.Text = string.sub(text4, 1, i)
    wait() --This is the speed of the text
end

wait(5)

game.ReplicatedStorage.Remotes.Gui3:FireServer()

script.Parent.Size.y = UDim2(0, 528, 0, 196)


end)    

2 answers

Log in to vote
0
Answered by
Despayr 505 Moderation Voter
4 years ago

That is because you are getting the length of 'Text', not 'Text3'.

Change the for loop line to

for i = 1, #text3 do

You made the same mistake with texts 2, 4, and 5

That is why it is getting cut off, because you are getting the length of text1

0
Thanks! That solved it. Quantrium 14 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

I think it's the for loop that is causing the problem. You're starting at an index of 1, but text starts at an index of 0.

An example:

H e l l o W o r l d 0 1 2 3 4 5 6 7 8 9 10

for i = 0, #text do
    script.Parent.Text = string.sub(text4, 1, i)
    wait() --This is the speed of the text
end

Answer this question