Optimizing your code is basically just making it as efficient and effective as possible! This means eradicating any deprecated functions, and using the best methods to go about doing tasks in your code.
Your code is a terrific example of something that can be optimized. The same code repeats. In cases like this, you can almost always use a loop. Loops loop over a section of code multiple times.
In this case, a numerical for loop would be perfect. You're "flickering" the Book's Transparency on and off 3 times. The syntax for a numerical for looks like this: for [variable] = [start],[end],[increment] do
[variable] is the variable you will set to track the iteration of the for loop. [start] is the starting point, [end] is the finishing point, and [increment] is how the for loop will count from [start] to [end]. The increment is defaulted to 1 if it's not provided.
So, since you're trying to count to 3, for 3 times of repeating the same code it would look like this:
Tool.Equipped:connect(function()
for i = 1,3 do
Book.Transparency = 1
wait(1)
Book.Transparency = 0
wait(1)
end
end)
1 comment
thx