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

How to script a click function that changes a text, using type writer?

Asked by 6 years ago
Edited 6 years ago

local noob = "Okay, here's our menu!"

function eh() for a = 5, #noob do script.Parent.Text = string.sub(noob, 2, a) wait(0.06) return eh() end end

script.Parent.MouseButton1Click:Connect(function(Clicked) eh() end)


This is the script i used, but its not working how it is supposed to, i'm a newbie in scripting

0
the "noob" variable is the text. utrabem 5 — 6y
0
Insert your code in a code block. To do that: Click on edit to edit this post. Click on the blue Lua icon which will insert 2 squiggly lines (~). Place your code in between these two lines. xPolarium 1388 — 6y
0
or press the lua button next to the inline code button theking48989987 2147 — 6y
0
Thanks everyone for the help! utrabem 5 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

If you want to make a function that types one letter at a time, you just make a new function that makes a copy of the original string (so that it doesn't override it) and then you use the string:sub() method to make it extract a portion of the string and then you do this with a for loop.

Consider the following code:

local text = "Hello World";
print(text:sub(1,5)) --> Hello

That codes prints the 5 first characters of the string ("Hello").

Now, you just need to make a numeric for loop that goes through each character and updates the TextLabel:

function writeText(text, textLabel)
    for current = 0, #text, 1 do
        textLabel.Text = text:sub(1,current)
    end
end

writeText("Hello World", script.Parent.TextLabel)

There you go.

0
Thank you! utrabem 5 — 6y
0
Would you mind accepting the answer as an answer? 1TheNoobestNoob 717 — 6y
Ad
Log in to vote
0
Answered by
Leamir 3138 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

Hello, utrabem!

I made some changes on your script, first of all, :Connect(function() is a function, so you don't need to call another function, to get a string lenght, use string.len() and if you want the letters to change on the string, use str = str2!

local noob = "Okay, here's our menu!"

script.Parent.MouseButton1Click:Connect(function()
    for a=1, string.len(noob)+1 do 
        script.Parent.Text = noob
        noob = string.sub(noob, 2)
        wait(0.06)
    end 
end)

Attention, I didn't made any changes on what your script does, this makes the words be REMOVED like somone writing...

Helpful links:

Roblox Dev - Lua Libraries - Strings

Good Luck with your games

0
*Thank you :)* utrabem 5 — 6y

Answer this question