How to change the contents of a TextLabel after being tweened?

Hey devs. I was wondering if any of you could help me with this.

I currently have my tween. Now I just want to change the text in the text label after the tween is executed.

Here is the explorer:

image

Here is the local script:

script.Parent.MouseEnter:Connect(function()
	script.Parent:TweenSize(UDim2.new(0, 400,0, 150), "Out", "Linear", 0.1, true)
end)

script.Parent.MouseLeave:Connect(function()
	script.Parent:TweenSize(UDim2.new(0, 218,0, 117), "Out", "Linear", 0.1, true)
end)

Thanks!

1 Like

Just add a callback:

script.Parent:TweenSize(UDim2.new(0, 400,0, 150), "Out", "Linear", 0.1, true, function(state)
		if state == Enum.TweenStatus.Completed then	
			script.Parent.Text = "DOne"
		end
	end)
1 Like

Do I add this to the same script?

1 Like

Yes that should replace the first tween code:

script.Parent.MouseEnter:Connect(function()
	script.Parent:TweenSize(UDim2.new(0, 400,0, 150), "Out", "Linear", 0.1, true, function(state)
		if state == Enum.TweenStatus.Completed then	
			script.Parent.Text = "DOne"
		end
	end)
end)
1 Like

Oh ok, but then it removes the tween of my mouse hovering. As you can see I want the first tween code as well as the function you posted to happen after I hover my mouse over it.

1 Like

Try this:

local Button = script.Parent


Button.MouseEnter:Connect(function()
	Button:TweenSize(UDim2.new(0, 400,0, 150), "Out", "Linear", 0.1, true, function(state)
	if state == Enum.TweenStatus.Completed then	
		script.Parent.Text = "Done"
	end
	end)
end)

Button.MouseLeave:Connect(function()
	Button:TweenSize(UDim2.new(0, 218,0, 117), "Out", "Linear", 0.1, true , function(state)
		if state == Enum.TweenStatus.Completed then	
			script.Parent.Text = "Message"
		end
		
	end)
end)
2 Likes
script.Parent.MouseEnter:Connect(function()
	script.Parent:TweenSize(UDim2.new(0, 400,0, 150), "Out", "Linear", 0.1, true)
    wait(0.1)
    script.Parent.Text = "Done!"
end)

script.Parent.MouseLeave:Connect(function()
	script.Parent:TweenSize(UDim2.new(0, 218,0, 117), "Out", "Linear", 0.1, true)
    wait(0.1)
    script.Parent.Text = "Hover!"
end)

It’s not the best solution, but it works. :smiley:

You should use task.wait() instead of wait.

1 Like

The microscopic amount that task.wait() loses is not that much. 0.015 milliseconds really isn’t much time, and nobody would know the difference.

1 Like

Thanks for the help!

@spvcta
@CommanderRanking
@domboss37

1 Like

You are welcome, have a nice day.

1 Like

You too.

1 Like