Question about this tween

So I basically want to create a point counter. That when you get a kill it will tween and show a (+x) amount of points.

Where it will tween from small to big back down to small.

My issue is that I’m currently doing a tween where it tweens from it’s current size to big, and when that tween completes it will tween back down to small and then it fades the opacity. But this is not working, it will bug out, stop tweening or not show. My code down below, how can I make this properly work? Thank you.

local killScore = game.Players.LocalPlayer.PlayerGui:WaitForChild("KillstreakGUI"):WaitForChild("KillScore")
local tweenInfo = TweenInfo.new(
	1, -- Time
	Enum.EasingStyle.Quad, -- EasingStyle
	Enum.EasingDirection.InOut, -- EasingDirection
	0, -- RepeatCount (when less than zero the tween will loop indefinitely)
	false, -- Reverses (tween will reverse once reaching it's goal)
	0 -- DelayTime
)

killText_Tween = TS:Create(killScore, tweenInfo, {Size = UDim2.new(0, 303, 0, 92)})

revertText = TS:Create(killScore, tweenInfo, {Size = UDim2.new(0, 130, 0, 31)})

reset = false

function onKill()

					killText_Tween.Completed:Connect(function()
						
						revertText.Completed:Connect(function()
							task.wait(2)
							if reset == true then
							for i = 1,10 do
								task.wait(0.1)
								killScore.TextTransparency += 0.1
							end
								killScore.Visible = false
							end
						end)
						revertText:Play()
					end)
					killText_Tween:Play()
					reset = true
end

Check out the TweenInfo.new constructor, it has a reverses: boolean parameter that will cause the tween to play forwards, and then in reverse in a single tween!

I’m not entirely sure if this will completely solve your problem, if it doesn’t come back and let us know.

(post deleted by author)

Yea that reverse is a good idea saves me having to create a 2nd tween. Although I’m still having the same issue. Problem is, even though I start a new tween. It doesn’t seem to cancel the current running one.

I tried to do

Tween:Cancel() and then followed by
Tween:Play()

But this just causes way more errors. Since I’m using reverse the size never returns to small (since it was cancelled before it could)

Any ideas? I just need the tween to start again every time I call x function.

Save the initial size of the target instance, and then if the tween is already playing, cancel it and set the size of the target instance to the initial value.

-- StarterPlayer.StarterPlayerScripts.LocalScript :: LocalScript

local TweenService = game:GetService("TweenService")
local UserInputService = game:GetService("UserInputService")

local Block = workspace.Block
local InitialSize, Tween = Block.Size, TweenService:Create(
    Block,
    TweenInfo.new(0.35, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, true),
    { Size = Block.Size * 2 }
)

UserInputService.InputBegan:Connect(function(input, processed)
    if processed or input.KeyCode ~= Enum.KeyCode.E then
        return
    elseif Tween.PlaybackState == Enum.PlaybackState.Playing then
        Tween:Cancel()
        Block.Size = InitialSize
    end
    
    Tween:Play()
end)

This video demonstrates the above code in action.

The penultimate argument of a TweenSize is whether or not a tween should override other tweens. Take a look - perhaps this is what you need to mess around with.

local Tween = gui:TweenSize(
	UDim2.new(0.5, 0, 0.5, 0),  
	Enum.EasingDirection.In,    
	Enum.EasingStyle.Quad,      
	2,                         
	true,                       -- try messing around with this. true = it will override, false = it won't override.
	callback                    
)

You may want to set the override parameter to false (the default), since you said that the GUI was bugging out / not completing - potentially because it was overriden by a secondary tween.

1 Like

Your video doesn’t work. And the problem with setting it to it’s initial size before tweening again is that the size will jump. Like if the size was large, and then you set to initial it will just instantly scale to small again which will look bad.

For me the video works…
charscharschars

It works now. Either way though, the problem that will happen is that the size will jump from big to small which wont look right.

Ah I thought that behaviour was what you were looking for, if not, I have another question to ask instead.

Are you instead then looking for a queue?

Not sure what you mean by que. But basically, I want this:

+15 points text label
Everytime my function is called
Starts at (small size) and tweens to larger size.

If the function is called again before the tween is over, it simply tweens from whatever size it’s at to the large size and then tweens back to original small size.

And ideally I need to add a fade opacity loop at the end once the points tween has finished playing, so the text can fade away until the function is called again (on player death)

You can use this code in onKill function.
local killScore = game.Players.LocalPlayer.PlayerGui:WaitForChild(“KillstreakGUI”):WaitForChild(“KillScore”)

local tweenInfo = TweenInfo.new(
1, – Time
Enum.EasingStyle.Quad, – EasingStyle
Enum.EasingDirection.InOut, – EasingDirection
0, – RepeatCount (when less than zero the tween will loop indefinitely)
false, – Reverses (tween will reverse once reaching it’s goal)
0 – DelayTime
)

function onKill()
killScore.Size = UDim2.new(0, 130, 0, 31)
killScore.TextTransparency = 0
killScore.Visible = true

local killText_Tween = TS:Create(killScore, tweenInfo, {Size = UDim2.new(0, 303, 0, 92)})
killText_Tween.Completed:Connect(function()
    local revertText = TS:Create(killScore, tweenInfo, {Size = UDim2.new(0, 130, 0, 31)})
    revertText.Completed:Connect(function()
        wait(2)
        for i = 1,10 do
            wait(0.1)
            killScore.TextTransparency += 0.1
        end
        killScore.Visible = false
    end)
    revertText:Play()
end)
killText_Tween:Play()

end

What happens when a new tween starts, and the for loop is still running and makes it transparent?