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

I made a close button for a gui. Now how would i make the gui fade out?

Asked by 7 years ago

Heres the code for it.

button = script.Parent.Parent.Parent
window = button.Parent.Parent.Parent

function onClicked(GUI)
window:remove()
end
script.Parent.MouseButton1Click:connect(onClicked)

2 answers

Log in to vote
2
Answered by
jotslo 273 Moderation Voter
7 years ago
Edited 7 years ago

I highly recommend you use a for loop instead as it is much shorter and looks much cleaner in your code.

button = script.Parent.Parent.Parent
window = button.Parent.Parent.Parent

function onClicked()
    for i = 1, 0, -.05 do
        window.BackgroundTransparency = i
        wait()
    end
    window:Destroy()
end

script.Parent.MouseButton1Click:connect(onClicked)

If your window is an image, use ImageTransparency as well.

button = script.Parent.Parent.Parent
window = button.Parent.Parent.Parent

function onClicked()
    for i = 1, 0, -.05 do
        window.BackgroundTransparency = i
        window.ImageTransparency = i
        wait()
    end
    window:Destroy()
end

script.Parent.MouseButton1Click:connect(onClicked)

You should always ensure that you use :Destroy() instead of :remove() as remove is deprecated and doesn't completely "remove" objects. If there are children to the window that also fade away, you will also need to refer to those in the script. I hope this helped!

Ad
Log in to vote
1
Answered by 7 years ago
button = script.Parent.Parent.Parent
window = button.Parent.Parent.Parent

function onClicked()
window.BackgroundTransparency = 0.9
wait(0.1)
window.BackgroundTransparency = 0.8
wait(0.1)
window.BackgroundTransparency = 0.7
wait(0.1)
window.BackgroundTransparency = 0.6
wait(0.1)
window.BackgroundTransparency = 0.5
wait(0.1)
window.BackgroundTransparency = 0.4
wait(0.1)
window.BackgroundTransparency = 0.3
wait(0.1)
window.BackgroundTransparency = 0.2
wait(0.1)
window.BackgroundTransparency = 0.1
wait(0.1)
window.BackgroundTransparency = 0
end
script.Parent.MouseButton1Click:connect(onClicked)

try that

Answer this question