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

How to make both the text transparency and image transparncy fade with a module script?

Asked by
hokyboy 270 Moderation Voter
3 years ago

Only 1 of the 2 things fade while both of the things should fade at the same time

Main Script

local TextModule = require(script.TextModule)


function MakeUIAlive()
    TextModule.fadetext(script.Parent.Warn1.ContiuneLabel)
    TextModule.FadeIcon(script.Parent.Warn1.HeartIcon)
end

Module Script

local TextModule = {}

function TextModule.fadetext(FlashIcon)
    local CurrTrans = 0
    while true do
        for count = 1,100 do
            CurrTrans = CurrTrans + .01
            FlashIcon.TextTransparency = CurrTrans
            FlashIcon.TextStrokeTransparency = CurrTrans
            wait(.01)
        end

        for count = 1,100 do
            CurrTrans = CurrTrans - .01
            FlashIcon.TextTransparency = CurrTrans
            FlashIcon.TextStrokeTransparency = CurrTrans
            wait(.01)
        end
    end
end

function TextModule.FadeIcon(FlashIcon)
    local CurrTrans = 0
    while true do
        for count = 1,100 do
            CurrTrans = CurrTrans + .01
            FlashIcon.ImageTransparency = CurrTrans
            wait(.01)
        end

        for count = 1,100 do
            CurrTrans = CurrTrans - .01
            FlashIcon.ImageTransparency = CurrTrans
            wait(.01)
        end
    end
end

return TextModule

1 answer

Log in to vote
1
Answered by 3 years ago

when you require the module you are essentially importing that code into the current script, so its like having back to back while/for loops and so it will wait for one to complete before running the next. To run them both you have several options:

1)You could create a new function in the module script that does both at the same time

2)You can run the functions from different scripts

3)You can run the functions on different threads, there are multiple ways of doing this so you should pick which fits you best, here are some resources for multi-threaded methods in Roblox Lua:

youtube video going through methods

Forumn Thread with some good replies

Ad

Answer this question