Different kinds of Tween Service you can use | How to use it.
Text Tween
What does this do?
Whenever you hover your mouse over something it adds spaces between every letter
Whenever you unhover your mouse over something the text is normal
Whenever you hover your mouse over something the text becomes all capitals
Example:
Hovered:
E X A M P L E
Not Hovered:
Example
Clicked
EXAMPLE > EXAMPL > EXAMP > EXAM > EXA > EX > E > “”
This is very useful for horror type games.
How to script it:
Lets use the basics, then we can get to advance later.
local text = script.Parent.Text -- Variable to access text easier
text.MouseEnter:Connect(function() -- Whenever you hover the mouse
text.Text = "E X A M P L E" -- Changes text
end)
text.MouseLeave:Connect(function() -- Whenever you unhover the mouse
text.Text = "Example" -- Changes text
end)
text.MouseButton1Click:Connect(function() -- Whenever you click
text.Text = "EXAMPL" -- Slowly changes text, Hovering is in moment.
task.wait(0.05) -- Waits 0.05 seconds
text.Text = "EXAMP"
task.wait(0.05)
text.Text = "EXAM"
task.wait(0.05)
test.Text = "EXA"
task.wait(0.05)
test.Text = "EX"
task.wait(0.05)
test.Text = "E"
task.wait(0.05)
test.Text = ""
end)
wait but wouldn’t using a for i loop be more practical?
local Text = "EXAMPLE"
local waitTime = 0.05
local length = string.len(Text)
for i = 1, length do
print(string.sub(Text, 1, length - (i - 1)))
task.wait(waitTime)
end
This is a pretty horrible tutorial, So much so that there are plenty of ways to simplify this. One of the ways @Jexemie already pointed out.
But I’ll simplify his code:
instead of subtracting the index value, you can instead have a -1 as a third argument, this makes it so the loop subtracts the index instead of adding, you can also remove the use of string.len() and replace it with #string, but that’s basically syntactic sugar.
for i = #Text,0,-1 do
task.wait(.05)
Text = string.sub(Text, 1, i)
end
This is bad practice and will ultimately lead to performance issues. This is also way more time-intensive on the developer and requires constant edits. An alternative method such as the ones shown by @Jexemie or @KdudeDev are recommended and much better to use.
The best method is MaxVisibleGraphemes, which sets how many characters are visible.
MaxVisibleGraphemes = 0 means no characters are visible, MaxVisibleGraphemes = -1 means all characters are visible, and MaxVisibleGraphemes = N means N characters are visible, N could be any number.
You would just decrease this property by 1 in a for loop with string.len as the amount of loops.
TextLabel.MaxVisibleGraphemes = string.len("EXAMPLE")
TextLabel.Text = "EXAMPLE"
for i = 1, string.len(TextLabel.Text) do
TextLabel.MaxVisibleGraphemes -= 1
end
Although this would work, a more proper effect would be with string.sub(), MaxVisibleGraphemes would just make the text invisible instead of making the text smaller.
Generally yes, People would use this to make a Basic typewriter effect as I stated in my Featured Post, but people would still use string.sub() more over MaxVisibleGraphemes, plus other ways that are more complicated (I wont go over them as this is straying) to get a more cooler effect that MaxVisibleGraphemes cannot do.
I’m not saying you’re wrong, I’m saying that its more uncommon to find this method.
this is the most insufficient code ive ever seen @Jexemie has a better example, you should learn more functions to upgrade your coding skills (like youtube tutorials, roblox creator docs)
function del()
local Text = text.Text
local TextMINUS = string.sub(Text, 1, i)
if not game:getService("RunService"):IsClient() then return print("NO CLIENT") end
if TextMinus then
Text = TextMINUS -- THIS WONT WORK :(
text.Text = TextMINUS
del()
end
del()
What if I want the TextLabel to say “Once upon a time, there were many un-documented developers on the Roblox platform that don’t know how to use the properties tab”? Will I repeat the semtemce over and over with one character missing?
For loops are part of The Basics. Learning how to be inefficient is not. Sorry, but I think you should learn some more scripting before making tutorials.
At least you are using task.wait() and not wait() lol.
But all seriousness it’s getting a little annoying with people making useless community “tutorials” that one could have learned by doing some basic research, with that in mind who exactly does this help?
Can’t say for beginners because if they are starting with insufficient code like such, it’s just dooming them from the start.
Please do proper research before making a community tutorial.