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
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.
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