Intro GUI unstable and slow

I’m trying to make an intro GUI that once a button is clicked it is faded out slowly, I made it and it was done but I noticed the text wasn’t being faded out, after I added the text removal, it later than has the text stroke problem where it wouldn’t fade out but I added that, after I added textstroketranparency to the script, this problem came where it seems very buggy and slow, I’m not sure why.

IntroScript = script.Parent.IntroFunction
Frame = script.Parent
Play = Frame.PlayButton

function PlayClicked()
print("Loading game...")
wait(.1)
for loop = 1,10 do
	wait(0.5)
	script.Parent.BackgroundTransparency = loop/10
	script.Parent.PlayButton.TextTransparency = loop/10
	script.Parent.PlayButton.TextStrokeTransparency = loop/10
	script.Parent.UpdatesButton.TextTransparency = loop/10
	script.Parent.UpdatesButton.TextStrokeTransparency = loop/10
	script.Parent.StoryButton.TextTransparency = loop/10
	script.Parent.StoryButton.TextStrokeTransparency = loop/10
	game:GetService("RunService").Stepped:Wait()
end
end

Play.MouseButton1Click:connect(PlayClicked)

Here is an example:
https://gyazo.com/518219f8cb3c7afe5b99f46de620d593

2 Likes

The reason that it appears to be fading slowly is because you have wait(0.5) inside of your for loop. Reducing 0.5 to a smaller value, such as 0.1, should make your UI fade out quicker.

4 Likes

Wow thanks! That seemed to be the issue, the wait time was a little too long.

2 Likes

I believe TweenService would do a better job.

local TweenService = game:GetService(“TweenService”)
local TweenSettings = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0)

for i,v in pairs(script.Parent:GetChildren()) do
    TweenService:Create(v,TweenSettings,{TextStrokeTransparency = 1, BackgroundTransparency = 1}):Play()
end

Edit:
Updated my code because of what @posatta said

(I typed this on my phone, unsure if this works)

5 Likes

That won’t work because TweenService.new isn’t a thing and TweenService:Create (what you probably meant) takes one instance for the first argument, not an array. He’d still need to loop through all children or specify each child like in the original code.

3 Likes

You should get rid of the wait statement altogether. You already have a wait statement at the bottom (waiting for Stepped to fire, which goes off at approximately 1/60th of a second, variable to change by framerate), so the wait statement at the top is unnecessary in its entirety. If that’s too fast, replace the Stepped statement with a wait using a lower interval or potentially change the end value of your numeric for loop, or do both.


All in all though I would honestly recommend moving to the TweenService to achieve this kind of fading effect as opposed to using an iteration loop, since that’s what the service is designed to do (among many other use cases). I’d strongly implore you to change over.

local TweenService = game:GetService("TweenService")
local FadeInfo = TweenInfo.new(1) -- Or whatever
-- Rest of your variables

function PlayClicked()
    for _, child in pairs(parent:GetChildren()) do
        TweenService:Create(child, FadeInfo, {property = goalAfterTween}):Play()
    end
    wait(FadeInfo.Time)
    -- something
end

Of course, this code is not a complete example and you’ll have to modify it to suit your needs, but this about sums it up. TweenService in the long run is a pleasurable and more efficient alternative to using numeric iteration loops to tween or fade.

4 Likes

Here’s an example TweenService in action(transparency).

6 Likes

Yeah TweenService should definitely be used in these scenarios.

I’ll definitely try that, by looking at how smooth and stable @anon81993163 demonstration was, seems it’ll perform a lot better.

1 Like