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

How would I change two variables in a loop where one counts up and the other counts down?

Asked by 5 years ago
Edited 5 years ago

So I'm working on a GUI and I'm working on a little cutscene in it. I'm making textlabels change transparency within a loop. I want to trigger another loop without stopping the present one and/or change two different variables in the same loop where one counts up and the other counts down.

This is what I have now.

function onPlayerAdded()
    local intro = menus.Intro
    intro.Visible = true
    local tew = intro["TEW"]
    local presents = intro.Presents
    intro.BackgroundTransparency = 0



    for i = 1, 0, -0.1 do --First loop 
        tew.TextTransparency = i
        wait(0.1)
    end

    for p = 1, 0, -0.1 do --Second loop
        presents.TextTransparency = p
        wait(0.1)
    end

end

Players.PlayerAdded:Connect(onPlayerAdded)

How would I change two variables in the same loop where one goes up and the other goes down? This was my attempts at figuring it out.


--Attempt 1 for p = 1, 0, -0.1 do --Second loop presents.TextTransparency = p wait(0.1) tew.TextTransparency = -p end --Attemp2 while tew.TextTransparency ~= 0 do tew.TextTransparency = tew.TextTransparency - 0.1 wait(0.1) end if tew.TextTransparency == 0 then while presents.TextTransparency ~= 0 do presents.TextTransparency = presents.TextTransparency - 0.1 tew.TextTransparency = tew.TextTransparency - 0.1 wait(0.1) end end

I'm out of ideas from here. What should I do?

1 answer

Log in to vote
1
Answered by
aazkao 787 Moderation Voter
5 years ago

This code will work already, but if you realise your tew doesnt change, its because transparency in roblox goes from 0 to 1 only

tew transparency will start from 0 and become invisible gradually and vice versa for presents


for p = 1,10 do --Second loop presents.TextTransparency = presents.TexTransparency - 0.1 wait(0.1) tew.TextTransparency =tew.TextTransparency + 0.1 wait(0.1) end

You do not have to use p as a variable for the transparency, you can define your own variables or just do what i do in the code

0
In fact your code at line 15 will work, just change line 17 to tew.TextTransparency = tew.TextTransparency + 0.1, not sure why you didnt want to do that aazkao 787 — 5y
0
I didnt think about it, I stayed up pretty late last night to finish some work. I made a few other mistakes. Maybe I shouldn't be scripting while running on midnight fuel... Thank you! BlauKitten 88 — 5y
0
No problem man aazkao 787 — 5y
Ad

Answer this question