function onClick() script.Parent.Text = "Clean Workspace" wait(1) script.Parent.Text = "Cleaning Workspace." wait(1) script.Parent.Text = "Cleaning Workspace.." wait(1) script.Parent.Text = "Cleaning Workspace..." wait(1) script.Parent.Text = "Done Cleaning Workspace(50)" wait(1) script.Parent.Text = "Done Cleaning Workspace(49)" wait(1) script.Parent.Text = "Done Cleaning Workspace(48)" wait(1) script.Parent.Text = "Done Cleaning Workspace(47)" wait(1) script.Parent.Text = "Done Cleaning Workspace(46)" wait(1) script.Parent.Text = "Done Cleaning Workspace(45)" wait(1) script.Parent.Text = "Done Cleaning Workspace(44)" wait(1) script.Parent.Text = "Done Cleaning Workspace(43)" wait(1) script.Parent.Text = "Done Cleaning Workspace(42)" wait(1) script.Parent.Text = "Done Cleaning Workspace(41)" wait(1) script.Parent.Text = "Done Cleaning Workspace(40)" wait(1) script.Parent.Text = "Done Cleaning Workspace(39)" wait(1) script.Parent.Text = "Done Cleaning Workspace(38)" wait(1) script.Parent.Text = "Done Cleaning Workspace(37)" wait(1) script.Parent.Text = "Done Cleaning Workspace(36)" wait(1) script.Parent.Text = "Done Cleaning Workspace(35)" wait(1) script.Parent.Text = "Done Cleaning Workspace(34)" wait(1) script.Parent.Text = "Done Cleaning Workspace(33)" wait(1) script.Parent.Text = "Done Cleaning Workspace(32)" wait(1) script.Parent.Text = "Done Cleaning Workspace(31)" wait(1) script.Parent.Text = "Done Cleaning Workspace(30)" wait(1) script.Parent.Text = "Done Cleaning Workspace(29)" wait(1) script.Parent.Text = "Done Cleaning Workspace(28)" wait(1) script.Parent.Text = "Done Cleaning Workspace(27)" wait(1) script.Parent.Text = "Done Cleaning Workspace(26)" wait(1) script.Parent.Text = "Done Cleaning Workspace(25)" wait(1) script.Parent.Text = "Done Cleaning Workspace(24)" wait(1) script.Parent.Text = "Done Cleaning Workspace(23)" wait(1) script.Parent.Text = "Done Cleaning Workspace(22)" wait(1) script.Parent.Text = "Done Cleaning Workspace(21)" wait(1) script.Parent.Text = "Done Cleaning Workspace(20)" wait(1) script.Parent.Text = "Done Cleaning Workspace(19)" wait(1) script.Parent.Text = "Done Cleaning Workspace(18)" wait(1) script.Parent.Text = "Done Cleaning Workspace(17)" wait(1) script.Parent.Text = "Done Cleaning Workspace(16)" wait(1) script.Parent.Text = "Done Cleaning Workspace(15)" wait(1) script.Parent.Text = "Done Cleaning Workspace(14)" wait(1) script.Parent.Text = "Done Cleaning Workspace(13)" wait(1) script.Parent.Text = "Done Cleaning Workspace(12)" wait(1) script.Parent.Text = "Done Cleaning Workspace(11)" wait(1) script.Parent.Text = "Done Cleaning Workspace(10)" wait(1) script.Parent.Text = "Done Cleaning Workspace(9)" wait(1) script.Parent.Text = "Done Cleaning Workspace(8)" wait(1) script.Parent.Text = "Done Cleaning Workspace(7)" wait(1) script.Parent.Text = "Done Cleaning Workspace(6)" wait(1) script.Parent.Text = "Done Cleaning Workspace(5)" wait(1) script.Parent.Text = "Done Cleaning Workspace(4)" wait(1) script.Parent.Text = "Done Cleaning Workspace(3)" wait(1) script.Parent.Text = "Done Cleaning Workspace(2)" wait(1) script.Parent.Text = "Done Cleaning Workspace(1)" wait(1) script.Parent.Text = "Done Cleaning Workspace" wait(1) script.Parent.Text = "Clean Workspace" wait(1) end script.Parent.MouseButton1Click:connect(onClick)
How do I make this shorter and how to i make it so that they have to wait 56 seconds before they can click it again or can click it after the text Clean Workspace shows again? I am very new to lua coding. THX
Important bit of coding advice; if there's ever a situation where you can achieve the same end-result without repeating the same line(s) of code, do it. Keep your code flexible, and clean. Some people find the phrase clean code very broad, and not very helpful in solving their "real problem", but it's quite the contrary. However, I won't personally be explaining the importance of clean code here, so for that I recommend you look at this article.
To get back on topic, a nice simple solution to the lengthy code you provided would be utilizing loops. A loop is a process handled by the computer for the programmer, which will execute or do a certain set of instructions forever, or until a condition is met. Different computer languages may implement loops differently, but they're all fundamentally the same. You'll generally hear about for and while loops, which (fundamentally speaking), are the only ones that really exist. Any other "kind" of loop, just adopts the same concept with different implementation (the repeat loop in Lua for example, which I've marked the differences between in this answer).
Point is, you can use a loop instead of repeating the same instruction on each line. I'll leave more in-depth explanations of how loops work and the differences between them, to your personal research or question asking. But to keep things short and simple, this would be a quick revision of your code:
-- I also recommend using variables whenever necessary (and they're necessary very often!) local parent = script.Parent -- Use "Connect" instead of "connect", the old method has since been deprecated. parent.MouseButton1Click:Connect(function() parent.Text = "Clean Workspace" -- Using a numeric for loop to add a period to the end of the string each iteration for i = 1, 3 do wait(1) parent.Text = parent.Text .. "." -- This process is called concatenation - the act of "adding" one string value to another. end -- Using the same numeric for loop, with it's optional step variant that determins the increment and direction of the for loop. for i = 50, 1, -1 do wait(1) -- Same concatenation process, but here we can use our control variable to display the loop's increment value parent.Text = "Done Cleaning Workspace (".. i ..")" end wait(1); parent.Text = "Done Cleaning Workspace" wait(1); parent.Text = "Clean Workspace" end)
If you have any questions, feel free to ask. Hope this helped.