TextLabels that moves if overlapping other TextLabels

I’m trying to get a TextLabel to move if another TextLabel is in the same position as it. This is so I can have multiple texts at once and use a Remote Event to create text without any problems. This script I made works but does not move the TextLabel after the first time. This makes newer TextLabels (that are cloned) overlap each other when they move up for the first time. I tried to constantly check if they were overlapping, but this made them infinitely move up. I have also tried to use a ChildAdded event to check every time a new TextLabel gets added, but this doesn’t work either (same problem).

Picture of how it looks like:
img1 :

My problem:

local function createText(color)
	--Clone a template TextLabel
	local TextLabel = script.Parent.TextLabel:Clone()
	local OriginalTextLabel = script.Parent.TextLabel
	--Check for other TextLabels 
	for i,v in pairs(script.Parent:GetChildren())do
		if v:IsA("TextLabel") then
			--If there is a different textlabel, tween up
			if  v ~= OriginalTextLabel then
				local tweenpos = TextLabel.Position - UDim2.new(0,0,0.08,0)
				local Tween = game:GetService("TweenService"):Create(v,TweenInfo.new(.5),{Position = tweenpos})
	TextLabel.Parent = script.Parent
	TextLabel.Name = "Message"

	TextLabel.TextTransparency = 0
	TextLabel.TextColor3 = color
	return TextLabel

MessageEvent.OnClientEvent:Connect(function(message, color)
	local text = ""
	--Call function to move the text if any are there
	local TextLabel = createText(color)
	--Scrolling text
	for i = 1,#message,1 do
		text = message:sub(1,i)
		TextLabel.Text = text
	--Fade text away and get rid of it
	local tweeninfo = TweenInfo.new(.5,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0)
	local goal = {}
	goal.TextTransparency = 1
	local fadeTween = TS:Create(TextLabel, tweeninfo, goal)

If anyone responds to this, thanks!

You have this at the end of your for loop that checks for existing text labels. Since it’s not parented yet, the loop misses it the first time (but afterwards it catches it the second time). Just move this before the loop and it should work properly.

1 Like

Thanks for responding, but I just tried your solution and it didn’t work. Instead, it moved when it detected the original TextLabel (the non-cloned one) and didn’t move at all after that.

Sorry it didn’t work. But I think I see another issue.

In this part of the loop, you are setting the TweenPosition equal to the new TextLabel position minus the offset you chose to move it up. If you want the text to move up after the first one then it should be v.Position for the TextLabel that needs to move, not the one you just cloned.

A better way is to put them in a frame with a UIListLayout so that any textlabels you add automatically gets put below existing ones and if any existing ones get removed, the rest get automatically moved up.


Thanks for the help! I think this solution would’ve been better than trying to do it manually with a script.