TweenService doesn't work again after it runs once

I am making a Ui TextLabel that fades in and out, however the fading is too fast and after it runs once it won’t run again.

local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local title = script.Parent
local area = game.Workspace.Area
local toggle = false

while true do wait(1)
    for i, section in pairs(area:GetChildren()) do
        local pos1,pos2 = (section.Position - (section.Size / 2)),(section.Position + (section.Size / 2))
        local region = Region3.new(pos1,pos2)
        local playersfound = game.Workspace:FindPartsInRegion3(region)

        for i, playersInArea in pairs(playersfound) do
            if playersInArea:FindFirstAncestor(player.Name) then
                toggle = true
                if title.Text == section.Name then
                    
                else 
                    title.Text = section.Name
                    title.Parent.Enabled = true
                    
                    local Info = TweenInfo.new(1)
                    local Tween = game:GetService("TweenService"):Create(script.Parent,Info,{TextTransparency=1})
                    Tween:Play()

                    print("Finished")
                end
            else 
                toggle = false
            end
        end
    end
end

I have tried to look for multiple ways to fix this problem and nothing has answered it. I’ve also asked multiple people and I haven’t gotten a reply yet. The current way Im making it fade in and out is through this:

local Info = TweenInfo.new(1)
local Tween = game:GetService("TweenService"):Create(script.Parent,Info,{TextTransparency=1})
Tween:Play()

I also have this one where it doesnt fade at all but it does work after 1 run.

local tweenTransparency = function(guiObject, targetTransparency, tweenTime)
   local tweenInfo = TweenInfo.new(tweenTime)
   local tween = game:GetService('TweenService'):Create(guiObject, tweenInfo, {Transparency = targetTransparency})
   tween:Play()
   wait(tweenTime) -- Remove if you want
end

The main thing I am trying to achieve right now is allowing it to replay and slowing it down.

Hi! I’m not sure if I get this correctly, but this seems to only make it fade out over 1 second, without making it fade in again. Any further tweens to make it fade out again won’t be visible.

Perhaps you want to reverse the tween also. This can be done with the TweenInfo

Instead of only passing the time to the tweenInfo constructor, you can also supply more optional arguments:

local tweenInfo = TweenInfo.new(
	2, -- Time
	Enum.EasingStyle.Linear, -- EasingStyle
	Enum.EasingDirection.Out, -- EasingDirection
	-1, -- RepeatCount (when less than zero the tween will loop indefinitely)
	true, -- Reverses (tween will reverse once reaching it's goal)
	0 -- DelayTime
)

However, to make it slow down, you may need to do new tweens each time, instead of just repeating.

Also note that you randomly go through the parts you found in the region and check if it’s a child of the player’s character (you may want to use part:IsDescendantOf(character) here instead). But the toggle is set by the last item in the loop, which is pretty random. I’m not sure if that will do as you intended it.

I tried your method. There are no errors with the script but the text just pops up instead of fading in. It also isn’t fading away and isn’t going back to being transparent.
The way I’m trying to do it by changing the transparency and text of a TextLabel in a Gui.image_2021-08-16_121740

Uhm, so you are setting the TextTransparency? In once example you gave, you set the Transparency, which won’t work on a TextLabel (it does have BackgroundTransparency, but note that despite what the docs say, it doesn’t affect the text transparency - and naturally also not the parent’s transparency).

TextTransparency should affect only the visibility of the letters. Only thing I can think of rn is that you use a textStroke, which acts kinda funky with TextTransparency. Probably worth a bug report, in fact.

Anyway, if you set the TextTransparency to 1, the textstroke will also not be visible any more. But if you set it to 0 and then to .9999999, the textstroke remains visible, even though the parameter in the properties window rounds it to 1. If it’s already 1 and you enter .9999999 it stays invisible at 1.

I imagine the same might happen if you tween it, though it’s pretty clearly visible because the inside of the letters does disappear.

I’m not sure what else it could be. Overall your code is a bit heavy, checking many regions every second, I didn’t go through what happens there exactly. You might want to at least use the break statement.

Does it print ‘Finished’? Try taking your tween outside this complicated while block and see if you can just get it to tween.

Note that transparency 1 means its invisible. Does your text start out as invisible? I’m not sure how it could pop up then, maybe you mean just the empty box from setting the .Enabled property on the parent, but your tween should make the text invisible, while leaving the background visible.

The way I intended it to work was that it starts invisible so its set to 1 then the tween would make it fade in all the way to 0 then wait(1) and go back to 1 transparency.

When the player enters a box in the group called area the text on the Ui would change to the boxes name. The text would then start fading in to show the text and then after a second or 2 it would then fade out back to invisible.

Well, you say the text just shows up visible, without tweening.. Even though you also say you set it to start invisible and then your tween seems to also make it invisible? Is that really the case?

And are you sure you are only talking about TextTransparency in all these cases, and not BackgroundTransparency or the Visible property (or for the screenGui the Enabled property)?

I’ve been doing trial and error runs, it works but there is a problem I don’t know how to fix. It’s hard to explain in words, if you want you can add me on discord and I can stream it to you. SlenderMan#6983

Nevermind I fixed it. Thank you for your help! It helped a lot when I was trying to fix multiple things.

1 Like