ACSII to Unicode Emoji converter


#1

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


#2

Make a table like the following

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

On your string, call

-- assuming the message is held on 'msg'
for i,p in pairs(convTable) do
msg = msg:gsub(i,p)
end

#3

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)

#4

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.


#5

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


#6

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)

#7

Didnโ€™t know about that one. Thanks!


#8

No problem man!

The more you know


#10

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:


#11

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


#12

Thanks! Iโ€™ll check it out soon


#13

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

#14

thanks!