#fade in function

1 messages · Page 1 of 1 (latest)

empty root
#

i've made my custom function to tween a frame and its descendants, but it sometimes doesnt work (only the viewport frames do)

#
--true means in, false means out
local function fade(frame: Frame, state: boolean)
    assert(frame:IsA("Frame"), `Expected {frame} to be a Frame.`)
    
    --type(state) doesnt work so hardcode it into true or false
    assert((state == true) or (state == false), `Expected {state} to be a boolean.`)
    
    local tweens: {[number]: Tween} = {}
    local fadePreferences: TweenInfo = state and fadeInPreferences or fadeOutPreferences
    local validInstances: {[number]: {["instance"]: any, ["property"]: string | number}} = {}
    
    for _, miniFolder in pairs(frame:GetChildren()) do
        if not miniFolder:IsA("Folder") then
            warn(`Expected {miniFolder} to be a Folder.`)
            continue
        end
        
        for _, gui in pairs(miniFolder:GetChildren()) do
            if not gui:IsA("GuiObject") then
                warn(`Expected {gui} to be a GUI.`)
                continue
            end
            
            --save and reset the old data
            local goals: {[string]: any} = {}

            --determine goals based on the gui's type
            if gui:IsA("ImageLabel") then
                if state then --fade in
                    goals.ImageTransparency = gui.ImageTransparency
                    gui.ImageTransparency = 1
                        
                else --fade out
                    goals.ImageTransparency = 1
                    table.insert(validInstances, {["instance"] = gui, ["property"] = "ImageTransparency"})
                end 
                    
                --yes i copy pasted this
            elseif gui:IsA("ImageButton") then
                gui.Interactable = state
                if state then --fade in
                    goals.ImageTransparency = gui.ImageTransparency
                    gui.ImageTransparency = 1

                else --fade out
                    ```
#
goals.ImageTransparency = 1
                    table.insert(validInstances, {["instance"] = gui, ["property"] = "ImageTransparency"})
                end 
                    
            elseif gui:IsA("TextLabel") then
                if state then --fade in
                    goals.TextTransparency = gui.TextTransparency
                    gui.TextTransparency = 1

                else --fade out
                    goals.TextTransparency = 1
                    table.insert(validInstances, {["instance"] = gui, ["property"] = "TextTransparency"})
                end 
                    
                    --yes i copy pasted this
            elseif gui:IsA("TextButton") then
                gui.Interactable = state
                if state then --fade in
                    goals.TextTransparency = gui.TextTransparency
                    gui.TextTransparency = 1

                else --fade out
                    goals.TextTransparency = 1
                    table.insert(validInstances, {["instance"] = gui, ["property"] = "TextTransparency"})
                end
            end
            
            table.insert(tweens, TweenService:Create(gui, fadePreferences, goals))
        end
    end
    
    --play the tweens
    if state then
        frame.Visible = true
        
        for _, tween in pairs(tweens) do tween:Play() end
    else
        for _, tween in pairs(tweens) do tween:Play() end
        
        task.wait(fadePreferences.Time)
        frame.Visible = false
        
        --reset everything back
        for _, touple in ipairs(validInstances) do touple.instance:ResetPropertyToDefault(touple.property) end
    end
end```
#

i'm using !strict so i have to be explicit, sorry for the huge block

#

use case:

#

i'd say that it has an ~85% to not bug when used

#

also, if it does happen to bug, the viewports stay visible

#

it's only bugging when fading in

next goblet
#

for

#

all of it

empty root
#

it's not really

#

i enjoy using it

next goblet
#

considering its just gonna yield forever

#

if its not there

empty root
#

but that's not the problem

#

can we ignore the asserts

#

there's no error messages so it's not the assert

empty root
#

do you have any other idea on why this doesnt work

next goblet
#

yeah

#

maybe ur doing it too fast

empty root
# empty root use case:

all the other functions do what they're supposed to do but nothing else is affected when the fade function doesn't work

empty root
next goblet
#

nah what I mean is maybe ur tryna call it too fast

#

does it ever do it on first fade in

empty root
#

dammit

empty root
#

it's about that 85% thing

#

it's not bugging on some specific numbers

#

I'll add in a renderstepped wait before fading them in

tough sentinel
empty root
next goblet
#

what I mean is

#

well

empty root
#

um

#

let's just try that renderstepped

#

it sounds like a great idea

tough sentinel
next goblet
empty root
#

if im using !strict, i might aswell

next goblet
#

strict is just for type checking

empty root
#

im using strict with the purpose of torturing myself

next goblet
#

strict isnt torture tho

#

I enjoy using strict

empty root
#

attempt 1/1 worked

#

2/2 worked

#

3/3

#

4th didnt work

#

what other ideas do you have

#

i could screenshare if that'd help you

empty root
empty root
next goblet
empty root
#

😔

next goblet
empty root
#

so i dont get a fix

#

broken hart

#

shart

next goblet
#

idk how ur starting it

#

but maybe its resetting it

empty root
#

wha?

#

wdym

next goblet
#

idk if ur firing a remote to client to start

#

or what

#

but maybe u start another one too soon after the last

#

and its still going

empty root
#

i use the command bar

#

i mean i used to

#

now i have a function that adds a proximity prompt to the npc

#

and you enable the proxy to start the dialogue

empty root
#

its still not fixed btw

#

id appreciate any help from anybody