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

[CLOSE] How do you shorten a code in a script?

Asked by 10 years ago

It looks trashy but this script makes an image GUI appear, then disappear.

while true do
    --GUI starts
    script.Parent.Transparency = 1
    script.Parent.ImageTransparency = 1
    script.Parent.BackgroundTransparency = 1
    wait(4)
    script.Parent.Transparency = 0.95
    script.Parent.ImageTransparency = 0.95
    script.Parent.BackgroundTransparency = 1
    wait(0.1)
    script.Parent.Transparency = 0.9
    script.Parent.ImageTransparency = 0.9
    script.Parent.BackgroundTransparency = 1
    wait(0.1)
    script.Parent.Transparency = 0.85
    script.Parent.ImageTransparency = 0.85
    script.Parent.BackgroundTransparency = 1
    wait(0.1)
    script.Parent.Transparency = 0.8
    script.Parent.ImageTransparency = 0.8
    script.Parent.BackgroundTransparency = 1
    wait(0.1)
    script.Parent.Transparency = 0.75
    script.Parent.ImageTransparency = 0.75
    script.Parent.BackgroundTransparency = 1
    wait(0.1)
    script.Parent.Transparency = 0.7
    script.Parent.ImageTransparency = 0.7
    script.Parent.BackgroundTransparency = 1
    wait(0.1)
    script.Parent.Transparency = 0.65
    script.Parent.ImageTransparency = 0.65
    script.Parent.BackgroundTransparency = 1
    wait(0.1)
    script.Parent.Transparency = 0.6
    script.Parent.ImageTransparency = 0.6
    script.Parent.BackgroundTransparency = 1
    wait(0.1)
    script.Parent.Transparency = 0.55
    script.Parent.ImageTransparency = 0.55
    script.Parent.BackgroundTransparency = 1
    wait(0.1)
    script.Parent.Transparency = 0.5
    script.Parent.ImageTransparency = 0.5
    script.Parent.BackgroundTransparency = 1
    wait(0.1)
    script.Parent.Transparency = 0.45
    script.Parent.ImageTransparency = 0.45
    script.Parent.BackgroundTransparency = 1
    wait(0.1)
    script.Parent.Transparency = 0.4
    script.Parent.ImageTransparency = 0.4
    script.Parent.BackgroundTransparency = 1
    wait(0.1)
    script.Parent.Transparency = 0.35
    script.Parent.ImageTransparency = 0.35
    script.Parent.BackgroundTransparency = 1
    wait(0.1)
    script.Parent.Transparency = 0.3
    script.Parent.ImageTransparency = 0.3
    script.Parent.BackgroundTransparency = 1
    wait(0.1)
    script.Parent.Transparency = 0.25
    script.Parent.ImageTransparency = 0.25
    script.Parent.BackgroundTransparency = 1
    wait(0.1)
    script.Parent.Transparency = 0.2
    script.Parent.ImageTransparency = 0.2
    script.Parent.BackgroundTransparency = 1
    wait(0.1)
    script.Parent.Transparency = 0.15
    script.Parent.ImageTransparency = 0.15
    script.Parent.BackgroundTransparency = 1
    wait(0.1)
    script.Parent.Transparency = 0.1
    script.Parent.ImageTransparency = 0.1
    script.Parent.BackgroundTransparency = 1
    wait(0.1)
    script.Parent.Transparency = 0.05
    script.Parent.ImageTransparency = 0.05
    script.Parent.BackgroundTransparency = 1
    --Image is at 0 transparency
    script.Parent.Transparency = 0
    script.Parent.BackgroundTransparency = 0
    script.Parent.BackgroundTransparency = 1
    wait(6) --how long the image will appear [you can change this value]
    script.Parent.Transparency = 0.05
    script.Parent.ImageTransparency = 0.05
    script.Parent.BackgroundTransparency = 1
    wait(0.1)
    script.Parent.Transparency = 0.1
    script.Parent.ImageTransparency = 0.1
    script.Parent.BackgroundTransparency = 1
    wait(0.1)
    script.Parent.Transparency = 0.15
    script.Parent.ImageTransparency = 0.15
    script.Parent.BackgroundTransparency = 1
    wait(0.1)
    script.Parent.Transparency = 0.2
    script.Parent.ImageTransparency = 0.2
    script.Parent.BackgroundTransparency = 1
    wait(0.1)
    script.Parent.Transparency = 0.25
    script.Parent.ImageTransparency = 0.25
    script.Parent.BackgroundTransparency = 1
    wait(0.1)
    script.Parent.Transparency = 0.3
    script.Parent.ImageTransparency = 0.3
    script.Parent.BackgroundTransparency = 1
    wait(0.1)
    script.Parent.Transparency = 0.35
    script.Parent.ImageTransparency = 0.35
    script.Parent.BackgroundTransparency = 1
    wait(0.1)
    script.Parent.Transparency = 0.4
    script.Parent.ImageTransparency = 0.4
    script.Parent.BackgroundTransparency = 1
    wait(0.1)
    script.Parent.Transparency = 0.45
    script.Parent.ImageTransparency = 0.45
    script.Parent.BackgroundTransparency = 1
    wait(0.1)
    script.Parent.Transparency = 0.5
    script.Parent.ImageTransparency = 0.5
    script.Parent.BackgroundTransparency = 1
    wait(0.1)
    script.Parent.Transparency = 0.55
    script.Parent.ImageTransparency = 0.55
    script.Parent.BackgroundTransparency = 1
    wait(0.1)
    script.Parent.Transparency = 0.6
    script.Parent.ImageTransparency = 0.6
    script.Parent.BackgroundTransparency = 1
    wait(0.1)
    script.Parent.Transparency = 0.65
    script.Parent.ImageTransparency = 0.65
    script.Parent.BackgroundTransparency = 1
    wait(0.1)
    script.Parent.Transparency = 0.7
    script.Parent.ImageTransparency = 0.7
    script.Parent.BackgroundTransparency = 1
    wait(0.1)
    script.Parent.Transparency = 0.75
    script.Parent.ImageTransparency = 0.75
    script.Parent.BackgroundTransparency = 1
    wait(0.1)
    script.Parent.Transparency = 0.8
    script.Parent.ImageTransparency = 0.8
    script.Parent.BackgroundTransparency = 1
    wait(0.1)
    script.Parent.Transparency = 0.85
    script.Parent.ImageTransparency = 0.85
    script.Parent.BackgroundTransparency = 1
    wait(0.1)
    script.Parent.Transparency = 0.9
    script.Parent.ImageTransparency = 0.9
    script.Parent.BackgroundTransparency = 1
    wait(0.1)
    script.Parent.Transparency = 0.95
    script.Parent.ImageTransparency = 0.95
    script.Parent.BackgroundTransparency = 1
    wait(0.1)
    script.Parent.Transparency = 1
    script.Parent.ImageTransparency = 1
    script.Parent.BackgroundTransparency = 1
    wait(0.1)
    --Image dissapears, intro completed.
    script.Parent:remove()
end

3 answers

Log in to vote
3
Answered by 10 years ago
wait(4) --Waits 4 seconds
for i = 1,0,-0.05 do --loop that goes from 1 to 0, incrementing by -0.05
    script.Parent.Transparency = i --Sets the transparency to i
    script.Parent.ImageTransparency = i
    wait(0.1)
end
wait(6) --how long the image will appear [you can change this value]
for i = 0,1,0.05 do --loop that goes from 0 to 1, incrementing by 0.05
    script.Parent.Transparency = i
    script.Parent.ImageTransparency = i
    wait(0.1)
end
script.Parent:Destroy() --Destroy() is a better choice than remove()

Hope this helped!

0
Welp, this works. Accepted answer. TegraDash 10 — 10y
0
Oh god, just use loops OniiCh_n 410 — 10y
Ad
Log in to vote
1
Answered by 10 years ago

Using loops, you can repeat the linear value change.

For example:

local sp = script.Parent

repeat wait(0.1)

    sp.Transparency = sp.Transparency - 0.05
    sp.Image.Transparency = sp.Image.Transparency - 0.05

until sp.Transparency == 0

repeat wait(0.1)

    sp.Transparency = sp.Transparency + 0.05
    sp.Image.Transparency = sp.Image.Transparency + 0.05

until sp.Transparency == 1
Log in to vote
0
Answered by 10 years ago

There is a way to make this shorter by using a loop or you can use a load string script, but that's hard to convert if you are not experienced in load string scripting.

Answer this question