How can I make my tween code more accurate and efficient?

This is my current code and it really looks like a mess and I feel like I’m not scripting this correctly. Is there any way I could redo the code to make it more efficient and accurate?

task.wait(3)
Tween:Play()
task.wait(0.45)
Text.Visible = false
task.wait(0.5)
a = 1
animation.Visible = true
	while true do
	animation.Text = "."
	task.wait(0.3)
	animation.Text = ".."
	task.wait(0.3)
	animation.Text = "..."
	task.wait(0.3)
	a = a + 1
	if a == 4 then
		break
	end
end
Tween2:Play()
task.wait(0.5)
Tween3:Play()

You could reduce this code block:

    animation.Text = "."
	task.wait(0.3)
	animation.Text = ".."
	task.wait(0.3)
	animation.Text = "..."
	task.wait(0.3)

down to a simpler for loop:

animation.Text = ""
for i = 1, 3 do
	animation.Text = animation.Text .. "." -- the '..' concatenates the existing string with another period.
	task.wait(0.3)
end

Furthermore, you could also reduce the while true do loop into another for loop

for i = 1, 3 do
	animation.Text = ""
	for i = 1, 3 do
		animation.Text = animation.Text .. "."
		task.wait(0.3)
	end
end
-- this loops the previous code three times.

if your use of task.wait() waits for the current tween to finish, you could replace it with Tween.Completed:Wait(), this will wait for the current tween to end before continuing the code.

I made it invisible after 0.45 so it doesn’t look funny when scaling down. Overall, I can try to adapt my code to the resources you have shared. I always have problems learning for loops so I’ll have to look into it more, thanks!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.