How would I simulate roblox's output stacking?

Hi,

I have a debug brick for my testers and I want the message to stack if it is the same as the previous output message.

Here’s the visual problem:


See how the output stacks but the custom one doesn’t.

Local Script:

--[ Services ]--
local LogService = game:GetService("LogService")

local SurfaceGUI = workspace.PublicConsole.SurfaceGui
local ScrollingFrame = SurfaceGUI.ScrollingFrame
--[ Settings ]--
MAX_CHARACTERS = nil -- max characters before it auto scales the text (the text size will change) 
TEXT_SIZE = 80

function CreateMessage(Message: string,MessageType)
	local TextLabel = Instance.new("TextLabel")
	
	TextLabel.BackgroundTransparency = 1
	
	if MessageType == Enum.MessageType.MessageWarning then 	
		TextLabel.TextColor = BrickColor.new("Yellow flip/flop")
	end
	
	if MessageType == Enum.MessageType.MessageOutput then
		TextLabel.TextColor = BrickColor.new("White")
	end
	
	if MessageType == Enum.MessageType.MessageError then
		TextLabel.TextColor = BrickColor.new("Red flip/flop")
	end
	
	if MessageType == Enum.MessageType.MessageInfo then
		TextLabel.TextColor = BrickColor.new("Baby blue")
	end
	
	TextLabel.AnchorPoint = Vector2.new(0.5,0.5)
	TextLabel.Size = UDim2.new(0.98, 0,0, 100)

	TextLabel.Font = Enum.Font.GothamSemibold
	TextLabel.Text = "▶ Console - "..Message
	TextLabel.TextSize = TEXT_SIZE

	if MAX_CHARACTERS then
		if string.len(TextLabel.Text) <= MAX_CHARACTERS then
			TextLabel.TextSize = TEXT_SIZE
		else
			TextLabel.TextScaled = true
		end
	end
	
	TextLabel.TextXAlignment = Enum.TextXAlignment.Left

	TextLabel.Parent = ScrollingFrame
end

LogService.MessageOut:Connect(function(Message: string,MessageType)
	CreateMessage(Message,MessageType)
end) 

You can store the message into a variable and check to see if the new message is the same as the old one:

local previousMessages = {} -- all the old messages that were sent to the console
local copies = 0 -- how many times the current message was sent (duplicates)

function CreateMessage(message: string, messageType: Enum.MessageType)
   if message == previousMessages[#previousMessages] then
      -- message is the same as the last one
      copies += 1 -- an additional copy
      -- do something to modify the text of the previous textlabel
      --...
      return -- stop the function from creating a duplicate message
   end

   --... create the message textlabel
   table.insert(previousMessages, message) -- add the new message to the list
   copies = 0 -- reset the copies counter
end
1 Like

This works but now how do I get a hold of the previous message textlabel?

You can also store that as a variable:

--...
local previousTextLabel = nil

function CreateMessage(...)
   --...
   previousTextLabel = TextLabel
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.