1 |
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)
1 |
This is the script i used, but its not working how it is supposed to, i'm a newbie in scripting
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:
1 | local text = "Hello World" ; |
2 | 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:
1 | function writeText(text, textLabel) |
2 | for current = 0 , #text, 1 do |
3 | textLabel.Text = text:sub( 1 ,current) |
4 | end |
5 | end |
6 |
7 | writeText( "Hello World" , script.Parent.TextLabel) |
There you go.
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
!
1 | local noob = "Okay, here's our menu!" |
2 |
3 | script.Parent.MouseButton 1 Click:Connect( function () |
4 | for a = 1 , string.len(noob)+ 1 do |
5 | script.Parent.Text = noob |
6 | noob = string.sub(noob, 2 ) |
7 | wait( 0.06 ) |
8 | end |
9 | 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