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

Make this script more efficient?

Asked by
RAYAN1565 691 Moderation Voter
10 years ago
for i=0, 1080, 1 do
    script.Parent.Frame.Position = script.Parent.Frame.Position - UDim2.new(0, 0, 0.005, 0)
    wait(0.1)
end

    script.Parent.ImageLabel2.BackgroundTransparency="0.1"      
    script.Parent.ImageLabel2.ImageTransparency="0.55"
        wait(0.1)
    script.Parent.ImageLabel2.BackgroundTransparency="0.2"  
    script.Parent.ImageLabel2.ImageTransparency="0.6"   
        wait(0.1)
    script.Parent.ImageLabel2.BackgroundTransparency="0.3"      
    script.Parent.ImageLabel2.ImageTransparency="0.65"
        wait(0.1)
    script.Parent.ImageLabel2.BackgroundTransparency="0.4"
    script.Parent.ImageLabel2.ImageTransparency="0.7"       
        wait(0.1)
    script.Parent.ImageLabel2.BackgroundTransparency="0.5"  
    script.Parent.ImageLabel2.ImageTransparency="0.75"  
        wait(0.1)   
    script.Parent.ImageLabel2.BackgroundTransparency="0.6"      
    script.Parent.ImageLabel2.ImageTransparency="0.8"
        wait(0.1)
    script.Parent.ImageLabel2.BackgroundTransparency="0.7"      
    script.Parent.ImageLabel2.ImageTransparency="0.85"
        wait(0.1)
    script.Parent.ImageLabel2.BackgroundTransparency="0.8"      
    script.Parent.ImageLabel2.ImageTransparency="0.9"
        wait(0.1)
    script.Parent.ImageLabel2.BackgroundTransparency="0.9"  
    script.Parent.ImageLabel2.ImageTransparency="0.95"  
        wait(0.1)
    script.Parent.ImageLabel2.BackgroundTransparency="1"    
    script.Parent.ImageLabel2.ImageTransparency="1" 

for i=0, 1, 0.05 do
    script.Parent.Parent.End.Volume = script.Parent.Parent.End.Volume - i   
    wait(0.1)
end     

    script.Parent.Parent.End:Pause()    

        wait(0.2)
    script.Parent:Destroy()

2 answers

Log in to vote
1
Answered by 6 years ago
for i=0, 1080, 1 do
    script.Parent.Frame.Position = script.Parent.Frame.Position - UDim2.new(0, 0, 0.005, 0)
    wait(0.1)
end



function lowerBackgroundTransparency()
    for b = 0, 1, 0.1 do
        script.Parent.BackgroundTransparency = b
        wait(0.1)
    end
end

function lowerImageTransparency()
    for i = 0.5, 1, 0.05 do
        script.Parent.ImageTransparency = i
        wait(0.1)
    end
end

Spawn(lowerBackgroundTransparency) -- Spawns this function
Spawn(lowerImageTransparency) -- Spawns this function

-- Might want to put a check here so it waits until they are both done.



for i=0, 1, 0.05 do
    script.Parent.Parent.End.Volume = script.Parent.Parent.End.Volume - i   
    wait(0.1)
end     

    script.Parent.Parent.End:Pause()    

        wait(0.2)
    script.Parent:Destroy()

Ad
Log in to vote
0
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
10 years ago

The best way I can think about to make this work would be by using Threading to make the loops run at the same time:

for i=0, 1080, 1 do
    script.Parent.Frame.Position = script.Parent.Frame.Position - UDim2.new(0, 0, 0.005, 0)
    wait(0.1)
end



function lowerBackgroundTransparency()
    for b = 0, 1, 0.1 do
        script.Parent.BackgroundTransparency = b
        wait(0.1)
    end
end

function lowerImageTransparency()
    for i = 0.5, 1, 0.05 do
        script.Parent.ImageTransparency = i
        wait(0.1)
    end
end

Spawn(lowerBackgroundTransparency) -- Spawns this function
Spawn(lowerImageTransparency) -- Spawns this function

-- Might want to put a check here so it waits until they are both done.



for i=0, 1, 0.05 do
    script.Parent.Parent.End.Volume = script.Parent.Parent.End.Volume - i   
    wait(0.1)
end     

    script.Parent.Parent.End:Pause()    

        wait(0.2)
    script.Parent:Destroy()

Answer this question