Adding images in between text

So I want a system that adds a image in between text so for example
A better example can be seen in Breaking Point. Type :cat: in that game and see the results.

Input: “I just got :oof:”
Output: "I just got image"

And no I am not gonna use the existing Rich text module cuz it makes soo many text labels it might cause lag.

1 Like

UI elements don’t generate much lag at all. Things that generate lag are things that require computation. Displaying a constant text thing is doing no computation, so it will cause no lag.

Just use Rich Text

dk how to use it to make my custom chat system

thats literally what I had in my head just repeated so not that helpful. What I have problem with is making repetition of images

Are you working with Roblox’s chat or a custom-made chat?

custom-made chat and so I got the image but only once now. what i need ur help in is to tell me how to get the number of replacements made by string.gsub… cuz IDK how to do that.

idk what u mean but like this

local str = "ye ye ye"
string.gsub(str."ye","ne") -- output: ne ne ne, timesreplaced: 3

yea like that lol at first didnt got what u meant.

WAIT NVM I AM SO SORRY! I now remember how to do that.

Hi! So we have encountered another problem.

script:

local label = script.Parent.TextLabel

local images = {
	[1] = {
		id = 579178678,
		name = ":ye:"
	}
}

local str = ":ye:DOES IT WORK?:ye:"

local finalstr,times = string.gsub(str,images[1].name,"")
local split = string.split(str,images[1].name)

local frame = Instance.new("Frame",label)
frame.AutomaticSize = Enum.AutomaticSize.XY
frame.BackgroundTransparency = 1
frame.Size = UDim2.new(0,0,0,0)
local uilistlayout = Instance.new("UIListLayout",frame)
uilistlayout.FillDirection = Enum.FillDirection.Horizontal
uilistlayout.SortOrder = Enum.SortOrder.Name

local num = 0
for i,v in pairs(split) do
	local line = Instance.new("TextLabel",frame)
	line.Name = num
	num += 1
	line.TextSize = label.TextSize
	line.TextColor3 = label.TextColor3
	line.BackgroundTransparency = 1
	line.AutomaticSize = Enum.AutomaticSize.XY
	line.Text = v
end
for i=1,times do
	local img = Instance.new("ImageLabel")
	img.Name = num
	num += 1
	img.Size = UDim2.fromOffset(label.TextSize,label.TextSize)
	img.Image = "rbxassetid://"..images[1].id
	img.BackgroundTransparency = 1
	img.Parent = frame
end

result:
image

expected results:
image

Well I accidentally came across this looking for something else.

The issue is it doesn’t go through and section out the string, it just counts them and tosses them at the end.

image

local label = script.Parent.TextLabel

local images = {
	[1] = {
		id = 579178678,
		name = ":ye:"
	}
}

local str = ":ye:DOES IT:ye:WORK?:ye:"
local count = 0

local imgFrame = Instance.new("Frame",label)
imgFrame.AutomaticSize = Enum.AutomaticSize.XY
imgFrame.BackgroundTransparency = 1
imgFrame.Size = UDim2.new(0,0,0,0)
local uiListLayout = Instance.new("UIListLayout",imgFrame)
uiListLayout.FillDirection = Enum.FillDirection.Horizontal
uiListLayout.SortOrder = Enum.SortOrder.Name


repeat 
	local startSpotColon, endSpotColon = string.find(str, ":")
	local foundImage, imgId, imgName = false, 0, ""
	for _,v in pairs(images) do
		local tempStart, tempEnd = string.find(str, v.name)
		if (startSpotColon == tempStart) then
			foundImage = true
			imgId = v.id
			imgEnd = tempEnd
		end
	end
	if foundImage then
		local tempStr = string.sub(str, 0, startSpotColon - 1)
		local line = Instance.new("TextLabel",imgFrame)
		line.Name = count
		count += 1
		line.TextSize = label.TextSize - 2
		line.TextColor3 = label.TextColor3
		line.BackgroundTransparency = 1
		line.AutomaticSize = Enum.AutomaticSize.XY
		line.Text = tempStr
		local img = Instance.new("ImageLabel")
		img.Name = count
		count += 1
		img.Size = UDim2.fromOffset(label.TextSize,label.TextSize)
		img.Image = "rbxassetid://"..images[1].id
		img.BackgroundTransparency = 1
		img.Parent = imgFrame
		str = string.sub(str, imgEnd + 1)
		print(str)
	else
		local tempStr = string.sub(str, 0, startSpotColon)
		local line = Instance.new("TextLabel",imgFrame)
		line.Name = count
		count += 1
		line.TextSize = label.TextSize - 2
		line.TextColor3 = label.TextColor3
		line.BackgroundTransparency = 1
		line.AutomaticSize = Enum.AutomaticSize.XY
		line.Text = tempStr
		str = string.sub(str, endSpotColon + 1)
		print(str)
	end
until not string.find(str, ":")
2 Likes

Yea that guy wont be responding to you anytime soon. (Account deleted)