Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How could I make this shorter?

Asked by 10 years ago

I am making a hint GUI but I want the script below smaller.

script.Parent.TextTransparency = 0.1
wait(0.1)
script.Parent.TextTransparency = 0.2
wait(0.1)
script.Parent.TextTransparency = 0.3
wait(0.1)
script.Parent.TextTransparency = 0.4
wait(0.1)
script.Parent.TextTransparency = 0.5
wait(0.1)
script.Parent.TextTransparency = 0.6
wait(0.1)
script.Parent.TextTransparency = 0.7
wait(0.1)
script.Parent.TextTransparency = 0.8
wait(0.1)
script.Parent.TextTransparency = 0.9
wait(0.1)
script.Parent.TextTransparency = 1

Any help?

4 answers

Log in to vote
1
Answered by 10 years ago

--Sorry if not coded right

for i=1,script.Parent.TextTransparency,0.1 do
script.Parent.TextTransparency=script.Parent.TextTransparncy-i
end
Ad
Log in to vote
-1
Answered by 10 years ago

Ok so since an administrator tells me to "Explain", I shall.

For loops are loops thats have either 2 or 3 arguments and are a variable by "i" or something else like "bacon". They run from the start number to the end number. The third argument can decide how much the variable goes up by every time it repeats itself.

Note: The third argument is optional. If you don't put a third argument, then it will add +1 by default.

Lets say u typed..

for cheese = 7,10,.1 do
    print(cheese)
end

or...

for cheese = 7,10 do
    print(cheese)
end

If you ran the script it should've went from 7 to 10 and adding .1 every time it looped in your output. If you ran the SECOND script it shouldve went 7,8,9,10. This goes back to my note. It automatically sets the third argument to 1 if nothing is there.

Now, the script I'm about to give you fixes your issue but I will guide you to how it works.

for i = 0,1,.1 do  --starts from zero and goes to one while adding .1 to i by every loop
    script.Parent.TextTransparency = i -- transparency is now the given value "i"
    wait(.1) --waits .1 seconds before redoing the loop and adding .1 to "i"
end
0
It works but, how would I make the transparency go down? Grenaderade 525 — 10y
0
change the second line to script.Parent.TextTransparency = 1 - i TochiWasHere 10 — 10y
Log in to vote
-2
Answered by
Prioxis 673 Moderation Voter
10 years ago

Here's the code

repeat
    script.Parent.TextTransparency = script.Parent.TextTransparency -0.1
until
script.Parent.TextTransparency == 1
Log in to vote
-3
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
10 years ago
for i = 1,10,1 do
    script.Parent.TextTransparency = i/10
    wait(.1)
end

Happy?

0
You just copied Tochi's script and took out the comments. ._. bloonblaster2000 55 — 10y
0
Actually no I didn't, I didn't even look at the previous answers. :/ I'll do it a different way if it'll make you happy.. Goulstem 8144 — 10y

Answer this question