ACSII to Unicode Emoji converter

I created a custom chat, how do I use string manipulation to convert text into emoji?

Examples:

: P = :stuck_out_tongue:

I like to walk : ) = I like to walk :grin:

Thanks!
(If there’s no auto convert feature, I can make my own dictionary)

If you use emojis in a string, it works btw
image

1 Like

Doesn’t work :C No errors, but it just doesn’t convert

Local Script if you want

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, false)

local colors = {'Brown'}

local convTable = {
[":P"] = "tongueEmojiHere",
[":)"] = "smileEmojiHere",
-- etc 
}

math.randomseed(os.time())
math.random()
math.random()
math.random()
math.random()

local player = game.Players.LocalPlayer
local nameColor = BrickColor.new(colors[math.random(1, #colors)]).Color
local messageColor = BrickColor.new('Institutional white').Color
local messageBox = script.Parent:WaitForChild('InputFrame'):FindFirstChild('MessageBox')
local UIS = game:GetService('UserInputService')
local event = game:GetService('ReplicatedStorage'):WaitForChild('Chatted')


if player.Name == 'astrelly' then
	nameColor = BrickColor.new('Gold').Color
end

function onInput(Input, GPE)
	if GPE then return end
	if Input.KeyCode == Enum.KeyCode.Slash then
		messageBox:CaptureFocus()
	end
end

function onFocus()
	if messageBox.Text == 'Press \'/\' to type a message...' then
		messageBox.Text = ''
	end
end

function onFocusLost(EnterPressed)
	if EnterPressed then
		if messageBox.Text ~= '' then
			event:FireServer(nameColor, messageBox.Text, messageColor)
			messageBox.Text = 'Press \'/\' to type a message...'
		else
			messageBox.Text = 'Press \'/\' to type a message...'
		end
	else
		if messageBox.Text == '' then
			messageBox.Text = 'Press \'/\' to type a message...'
		end
	end
end


function addLine(message, Label)
	local chatBox = script.Parent:FindFirstChild('Frame')
	local newMessage = Instance.new('Frame', chatBox)

	newMessage.Size = UDim2.new(1, -10, 0, 20)
	newMessage.Position = UDim2.new(0, 5, 1, -25)
	newMessage.BackgroundTransparency = 1
	newMessage.ClipsDescendants = true
	local lineMessage = ''
	while Label.TextFits == false do
		lineMessage = string.sub(message, -1) .. lineMessage
		message = string.sub(message, 1, string.len(message) - 1)
		Label.Text = message
	end
	
	for _, oldMessage in pairs (chatBox:GetChildren()) do
		if oldMessage ~= newMessage then
			oldMessage.Position = oldMessage.Position + UDim2.new(0, 0, 0, -newMessage.AbsoluteSize.Y + 5)
		end
	end
	
	local messageLabel = Instance.new('TextLabel', newMessage)
	messageLabel.BackgroundTransparency = 1
	messageLabel.Font = 'Cartoon'
	messageLabel.TextColor3 = messageColor
	messageLabel.FontSize = 'Size18'
	messageLabel.TextXAlignment = 'Left'
	messageLabel.TextStrokeTransparency = 0
	messageLabel.TextStrokeColor3 = Color3.fromRGB(102, 102, 102)

for i,p in pairs(convTable) do
messageLabel.Text = lineMessage:gsub(i,p)
end

	messageLabel.Size = UDim2.new(1, -10, 0, 20)
	messageLabel.Position = UDim2.new(0, 5, 0, 0)
	
	local LineTag = Instance.new('StringValue', messageLabel.Parent)
	LineTag.Name = 'LineTag'
	local LineTag2 =Instance.new('StringValue', Label.Parent)
	LineTag2.Name = 'LineTag'
	
	if messageLabel.TextFits ~= true then
		addLine(lineMessage, messageLabel)
		print('addingling')
	else
		for _, oldMessage in pairs (chatBox:GetChildren()) do
			if not oldMessage:FindFirstChild('LineTag') then
				oldMessage.Position = oldMessage.Position + UDim2.new(0, 0, 0, -newMessage.AbsoluteSize.Y + 5)
			end
		end
	end
	LineTag:Destroy()
	LineTag2:Destroy()
end

function onEvent(sender, nameColor, message, messageColor)
	local chatBox = script.Parent:FindFirstChild('Frame')
	local newMessage = Instance.new('Frame', chatBox)
	newMessage.Size = UDim2.new(1, -10, 0, 20)
	newMessage.Position = UDim2.new(0, 5, 1, -25)
	newMessage.BackgroundTransparency = 1
	newMessage.ClipsDescendants = true
						
	local nameLabel = Instance.new('TextLabel', newMessage)
	nameLabel.BackgroundTransparency = 1
	nameLabel.Font = 'Cartoon'
	nameLabel.TextColor3 = nameColor
	nameLabel.FontSize = 'Size18'
	nameLabel.TextXAlignment = 'Left'
	nameLabel.Text = '[' .. sender.Name .. ']:'
	nameLabel.Size = UDim2.new(0, nameLabel.TextBounds.X + 5, 0, 20)
	nameLabel.TextStrokeTransparency = 1
						
	local messageLabel = Instance.new('TextLabel', newMessage)
	messageLabel.BackgroundTransparency = 1
	messageLabel.Font = 'Cartoon'
	messageLabel.TextColor3 = messageColor
	messageLabel.FontSize = 'Size18'
	messageLabel.TextXAlignment = 'Left'
	messageLabel.Text = message
	messageLabel.Size = UDim2.new(1, -nameLabel.AbsoluteSize.X, 0, 20)
	messageLabel.Position = nameLabel.Position + UDim2.new(0, nameLabel.AbsoluteSize.X, 0, 0)
	messageLabel.TextStrokeTransparency = 0
	messageLabel.TextStrokeColor3 = Color3.fromRGB(102, 102, 102)
	
	if messageLabel.TextFits ~= true then
		addLine(message, messageLabel)
	else
		for _, oldMessage in pairs (chatBox:GetChildren()) do
			if oldMessage ~= newMessage then
				oldMessage.Position = oldMessage.Position + UDim2.new(0, 0, 0, -newMessage.AbsoluteSize.Y + 5)
			end
		end
	end
end


UIS.InputBegan:connect(onInput)
event.OnClientEvent:connect(onEvent)
messageBox.Focused:connect(onFocus)
messageBox.FocusLost:connect(onFocusLost)

It seems like you didn’t change the table @Flubberlutsch provided to you, unless that was intentional. You will need to paste the emojis where he said tongueEmojiHere, and smileEmojiHere.


Just some advice, but rather than doing

math.randomseed(os.time())
math.random()
math.random()
math.random()
math.random()

you should utilize the new Random class, which is guaranteed to provide a different number each time.

4 Likes

I was just testing it, and keep other topics to that topic. thanks for the advice anyways

It was related, but okay. Try this.

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, false)

local colors = {'Brown'}

local convTable = {
[":P"] = "tongueEmojiHere",
[":)"] = "smileEmojiHere",
-- etc 
}

math.randomseed(os.time())
math.random()
math.random()
math.random()
math.random()

local player = game.Players.LocalPlayer
local nameColor = BrickColor.new(colors[math.random(1, #colors)]).Color
local messageColor = BrickColor.new('Institutional white').Color
local messageBox = script.Parent:WaitForChild('InputFrame'):FindFirstChild('MessageBox')
local UIS = game:GetService('UserInputService')
local event = game:GetService('ReplicatedStorage'):WaitForChild('Chatted')


if player.Name == 'astrelly' then
	nameColor = BrickColor.new('Gold').Color
end

function onInput(Input, GPE)
	if GPE then return end
	if Input.KeyCode == Enum.KeyCode.Slash then
		messageBox:CaptureFocus()
	end
end

function onFocus()
	if messageBox.Text == 'Press \'/\' to type a message...' then
		messageBox.Text = ''
	end
end

function onFocusLost(EnterPressed)
	if EnterPressed then
		if messageBox.Text ~= '' then
			event:FireServer(nameColor, messageBox.Text, messageColor)
			messageBox.Text = 'Press \'/\' to type a message...'
		else
			messageBox.Text = 'Press \'/\' to type a message...'
		end
	else
		if messageBox.Text == '' then
			messageBox.Text = 'Press \'/\' to type a message...'
		end
	end
end


function addLine(message, Label)
	local chatBox = script.Parent:FindFirstChild('Frame')
	local newMessage = Instance.new('Frame', chatBox)

	newMessage.Size = UDim2.new(1, -10, 0, 20)
	newMessage.Position = UDim2.new(0, 5, 1, -25)
	newMessage.BackgroundTransparency = 1
	newMessage.ClipsDescendants = true
	local lineMessage = ''
	while Label.TextFits == false do
		lineMessage = string.sub(message, -1) .. lineMessage
		message = string.sub(message, 1, string.len(message) - 1)
		Label.Text = message
	end
	
	for _, oldMessage in pairs (chatBox:GetChildren()) do
		if oldMessage ~= newMessage then
			oldMessage.Position = oldMessage.Position + UDim2.new(0, 0, 0, -newMessage.AbsoluteSize.Y + 5)
		end
	end
	
	local messageLabel = Instance.new('TextLabel', newMessage)
	messageLabel.BackgroundTransparency = 1
	messageLabel.Font = 'Cartoon'
	messageLabel.TextColor3 = messageColor
	messageLabel.FontSize = 'Size18'
	messageLabel.TextXAlignment = 'Left'
	messageLabel.TextStrokeTransparency = 0
	messageLabel.TextStrokeColor3 = Color3.fromRGB(102, 102, 102)

	for input,emoji in next, convTable do
		messageLabel.Text = message:gsub(input, emoji)
	end

	messageLabel.Size = UDim2.new(1, -10, 0, 20)
	messageLabel.Position = UDim2.new(0, 5, 0, 0)
	
	local LineTag = Instance.new('StringValue', messageLabel.Parent)
	LineTag.Name = 'LineTag'
	local LineTag2 =Instance.new('StringValue', Label.Parent)
	LineTag2.Name = 'LineTag'
	
	if messageLabel.TextFits ~= true then
		addLine(lineMessage, messageLabel)
		print('addingling')
	else
		for _, oldMessage in pairs (chatBox:GetChildren()) do
			if not oldMessage:FindFirstChild('LineTag') then
				oldMessage.Position = oldMessage.Position + UDim2.new(0, 0, 0, -newMessage.AbsoluteSize.Y + 5)
			end
		end
	end
	LineTag:Destroy()
	LineTag2:Destroy()
end

function onEvent(sender, nameColor, message, messageColor)
	local chatBox = script.Parent:FindFirstChild('Frame')
	local newMessage = Instance.new('Frame', chatBox)
	newMessage.Size = UDim2.new(1, -10, 0, 20)
	newMessage.Position = UDim2.new(0, 5, 1, -25)
	newMessage.BackgroundTransparency = 1
	newMessage.ClipsDescendants = true
						
	local nameLabel = Instance.new('TextLabel', newMessage)
	nameLabel.BackgroundTransparency = 1
	nameLabel.Font = 'Cartoon'
	nameLabel.TextColor3 = nameColor
	nameLabel.FontSize = 'Size18'
	nameLabel.TextXAlignment = 'Left'
	nameLabel.Text = '[' .. sender.Name .. ']:'
	nameLabel.Size = UDim2.new(0, nameLabel.TextBounds.X + 5, 0, 20)
	nameLabel.TextStrokeTransparency = 1
						
	local messageLabel = Instance.new('TextLabel', newMessage)
	messageLabel.BackgroundTransparency = 1
	messageLabel.Font = 'Cartoon'
	messageLabel.TextColor3 = messageColor
	messageLabel.FontSize = 'Size18'
	messageLabel.TextXAlignment = 'Left'
	for input,emoji in next, convTable do -- replace text with emojis
		messageLabel.Text = message:gsub(input, emoji)
	end
	messageLabel.Text = message
	messageLabel.Size = UDim2.new(1, -nameLabel.AbsoluteSize.X, 0, 20)
	messageLabel.Position = nameLabel.Position + UDim2.new(0, nameLabel.AbsoluteSize.X, 0, 0)
	messageLabel.TextStrokeTransparency = 0
	messageLabel.TextStrokeColor3 = Color3.fromRGB(102, 102, 102)
	
	if messageLabel.TextFits ~= true then
		addLine(message, messageLabel)
	else
		for _, oldMessage in pairs (chatBox:GetChildren()) do
			if oldMessage ~= newMessage then
				oldMessage.Position = oldMessage.Position + UDim2.new(0, 0, 0, -newMessage.AbsoluteSize.Y + 5)
			end
		end
	end
end


UIS.InputBegan:connect(onInput)
event.OnClientEvent:connect(onEvent)
messageBox.Focused:connect(onFocus)
messageBox.FocusLost:connect(onFocusLost)
1 Like

Didn’t know about that one. Thanks!

1 Like

No problem man!

The more you know

This is actually really simple you can do this with a few lines. I’ll explain how.
So first of you will need one thing, a thing module of emojis that can be converted.

Here is what I use to check what emoji is what. Here is the model from Roblox.

Now here is the code that will convert the message piece that has an emoji into an emoji.

Message = string.gsub(Message, "(:[%w_]+:)", function (a) return EmojiList[a] or a end)

Just make the message become that before it is sent in the chat. EmojiList is just local EmojiList = require(script:WaitForChild("EmojiList")) in my script. Now you’re done! You should have emojis. Now obviously you may not want the EmojiList i’ve given from the model so here is an example list you can use.

local EmojiList = {
	{":)", "😃"},
}

for i, v in ipairs(EmojiList) do
	EmojiList[v[1]] = v[2]
end

return EmojiList

Once you’ve done all this you’re done. So if you used my example in the chat if you said “Hello :)” it would become “Hello :smile:”, or if you used the model I provided, saying "Hello :smile:" it would become “Hello :smile:

Credit to @FearMeIAmLag because the entire EmojiList model was taken off of him. :stuck_out_tongue:

1 Like

I also went ahead and updated your existing code for you.

Here is the code:

Code
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, false)

local colors = {'Brown'}

local convTable = require(script.List)

math.randomseed(os.time())
math.random()
math.random()
math.random()
math.random()

local player = game.Players.LocalPlayer
local nameColor = BrickColor.new(colors[math.random(1, #colors)]).Color
local messageColor = BrickColor.new('Institutional white').Color
local messageBox = script.Parent:WaitForChild('InputFrame'):FindFirstChild('MessageBox')
local UIS = game:GetService('UserInputService')
local event = game:GetService('ReplicatedStorage'):WaitForChild('Chatted')


if player.Name == 'astrelly' then
	nameColor = BrickColor.new('Gold').Color
end

function onInput(Input, GPE)
	if GPE then return end
	if Input.KeyCode == Enum.KeyCode.Slash then
		messageBox:CaptureFocus()
	end
end

function onFocus()
	if messageBox.Text == 'Press \'/\' to type a message...' then
		messageBox.Text = ''
	end
end

function onFocusLost(EnterPressed)
	if EnterPressed then
		if messageBox.Text ~= '' then
			event:FireServer(nameColor, messageBox.Text, messageColor)
			messageBox.Text = 'Press \'/\' to type a message...'
		else
			messageBox.Text = 'Press \'/\' to type a message...'
		end
	else
		if messageBox.Text == '' then
			messageBox.Text = 'Press \'/\' to type a message...'
		end
	end
end


function addLine(message, Label)
	local chatBox = script.Parent:FindFirstChild('Frame')
	local newMessage = Instance.new('Frame', chatBox)

	newMessage.Size = UDim2.new(1, -10, 0, 20)
	newMessage.Position = UDim2.new(0, 5, 1, -25)
	newMessage.BackgroundTransparency = 1
	newMessage.ClipsDescendants = true
	local lineMessage = ''
	while Label.TextFits == false do
		lineMessage = string.sub(message, -1) .. lineMessage
		message = string.sub(message, 1, string.len(message) - 1)
		Label.Text = message
	end
	
	for _, oldMessage in pairs (chatBox:GetChildren()) do
		if oldMessage ~= newMessage then
			oldMessage.Position = oldMessage.Position + UDim2.new(0, 0, 0, -newMessage.AbsoluteSize.Y + 5)
		end
	end
	
	local messageLabel = Instance.new('TextLabel', newMessage)
	messageLabel.BackgroundTransparency = 1
	messageLabel.Font = 'Cartoon'
	messageLabel.TextColor3 = messageColor
	messageLabel.FontSize = 'Size18'
	messageLabel.TextXAlignment = 'Left'
	messageLabel.TextStrokeTransparency = 0
	messageLabel.TextStrokeColor3 = Color3.fromRGB(102, 102, 102)

for i,p in pairs(convTable) do
messageLabel.Text = lineMessage:gsub(i,p)
end

	messageLabel.Size = UDim2.new(1, -10, 0, 20)
	messageLabel.Position = UDim2.new(0, 5, 0, 0)
	
	local LineTag = Instance.new('StringValue', messageLabel.Parent)
	LineTag.Name = 'LineTag'
	local LineTag2 =Instance.new('StringValue', Label.Parent)
	LineTag2.Name = 'LineTag'
	
	if messageLabel.TextFits ~= true then
		addLine(lineMessage, messageLabel)
		print('addingling')
	else
		for _, oldMessage in pairs (chatBox:GetChildren()) do
			if not oldMessage:FindFirstChild('LineTag') then
				oldMessage.Position = oldMessage.Position + UDim2.new(0, 0, 0, -newMessage.AbsoluteSize.Y + 5)
			end
		end
	end
	LineTag:Destroy()
	LineTag2:Destroy()
end

function onEvent(sender, nameColor, message, messageColor)
	local chatBox = script.Parent:FindFirstChild('Frame')
	local newMessage = Instance.new('Frame', chatBox)
	newMessage.Size = UDim2.new(1, -10, 0, 20)
	newMessage.Position = UDim2.new(0, 5, 1, -25)
	newMessage.BackgroundTransparency = 1
	newMessage.ClipsDescendants = true
						
	local nameLabel = Instance.new('TextLabel', newMessage)
	nameLabel.BackgroundTransparency = 1
	nameLabel.Font = 'Cartoon'
	nameLabel.TextColor3 = nameColor
	nameLabel.FontSize = 'Size18'
	nameLabel.TextXAlignment = 'Left'
	nameLabel.Text = '[' .. sender.Name .. ']:'
	nameLabel.Size = UDim2.new(0, nameLabel.TextBounds.X + 5, 0, 20)
	nameLabel.TextStrokeTransparency = 1
						
	local messageLabel = Instance.new('TextLabel', newMessage)
	messageLabel.BackgroundTransparency = 1
	messageLabel.Font = 'Cartoon'
	messageLabel.TextColor3 = messageColor
	messageLabel.FontSize = 'Size18'
	messageLabel.TextXAlignment = 'Left'
	messageLabel.Text = string.gsub(message, "(:[%w_]+:)", function (a) return convTable[a] or a end)
	messageLabel.Size = UDim2.new(1, -nameLabel.AbsoluteSize.X, 0, 20)
	messageLabel.Position = nameLabel.Position + UDim2.new(0, nameLabel.AbsoluteSize.X, 0, 0)
	messageLabel.TextStrokeTransparency = 0
	messageLabel.TextStrokeColor3 = Color3.fromRGB(102, 102, 102)
	
	if messageLabel.TextFits ~= true then
		addLine(message, messageLabel)
	else
		for _, oldMessage in pairs (chatBox:GetChildren()) do
			if oldMessage ~= newMessage then
				oldMessage.Position = oldMessage.Position + UDim2.new(0, 0, 0, -newMessage.AbsoluteSize.Y + 5)
			end
		end
	end
end


UIS.InputBegan:connect(onInput)
event.OnClientEvent:connect(onEvent)
messageBox.Focused:connect(onFocus)
messageBox.FocusLost:connect(onFocusLost)

The convTable variable was switched to require(script.List), that is just the example list I gave in my above reply. If you’d like to take the code I updated in studio here it is on Roblox. The model: https://www.roblox.com/catalog/01916705841/redirect

1 Like

Thanks! I’ll check it out soon

I made a system for this

I store the emojis in a module:

local module = {
	{["Pattern"] = "/shrug",	["Emoji"] = "¯%\_(ツ)_/¯"},
	{["Pattern"] = ":eye:",		["Emoji"] = "👁️"},
	{["Pattern"] = ":eyes:",	["Emoji"] = "👀"},
	{["Pattern"] = ":fire:",	["Emoji"] = "🔥"},
	{["Pattern"] = ":100:",		["Emoji"] = "💯"},
	{["Pattern"] = ":thinking:",	["Emoji"] = "🤔"},
	{["Pattern"] = ":ok_hand:",	["Emoji"] = "👌"},
	{["Pattern"] = ":hug:",		["Emoji"] = "🤗"},
	{["Pattern"] = ">:%)",		["Emoji"] = "😈"},
	{["Pattern"] = ">:%(",		["Emoji"] = "😠"},
	{["Pattern"] = "B%)",		["Emoji"] = "😎"},
	{["Pattern"] = ":%)",		["Emoji"] = "🙂"},
	{["Pattern"] = ":/",		["Emoji"] = "😕"},
	{["Pattern"] = ":%(",		["Emoji"] = "🙁"},
	{["Pattern"] = "':D",		["Emoji"] = "😅"},
	{["Pattern"] = ":D",		["Emoji"] = "😄"},
	{["Pattern"] = ":[oO]+",	["Emoji"] = "😮"},
	{["Pattern"] = ":P%$",		["Emoji"] = "🤑"},
	{["Pattern"] = ":P",		["Emoji"] = "😛"},
	{["Pattern"] = ";P",		["Emoji"] = "😜"},
	{["Pattern"] = ":[xX]+",	["Emoji"] = "🤐"},
	{["Pattern"] = "%._%.",		["Emoji"] = "😐"},
	{["Pattern"] = ">_>",		["Emoji"] = "😒"},
	{["Pattern"] = "<_<",		["Emoji"] = "😒"},
	{["Pattern"] = "%-_%-",		["Emoji"] = "😑"},
	{["Pattern"] = "x_x",		["Emoji"] = "😵"},
}
return module

And then I use this to apply these to the actual text

local emojis = require(script.EmojiModule)
function emojifi(s)
	for i = 1,#emojis do
		s = string.gsub(s,emojis[i]["Pattern"],emojis[i]["Emoji"])
	end
	return s
end
3 Likes

thanks!

1 Like