Country Code to Emoji

Hello!

I created a simple and easy function for anyone to turn a country code into an emoji!

You can use this however you would like, for aesthetics,global chat messages, nametags, you get the idea!

Function:

function countryCodeToEmoji(countryCode)

	countryCode = countryCode:upper()

	local firstLetter = countryCode:sub(1, 1)
	local secondLetter = countryCode:sub(2, 2)

	local firstEmoji = utf8.char(0x1F1E6 + (firstLetter:byte() - 65))
	local secondEmoji = utf8.char(0x1F1E6 + (secondLetter:byte() - 65))

	return firstEmoji .. secondEmoji
	
end

Pretty simple, hope it helps someone!

Usage:

local LocalizationService = game:GetService("LocalizationService")
local Player = game.Players.LocalPlayer

local result, code = pcall(function()
	return LocalizationService:GetCountryRegionForPlayerAsync(Player)
end)

The code above will get you the country code of the LocalPlayer. If the player is from the United States it will return “US”

local LocalizationService = game:GetService("LocalizationService")
local Player = game.Players.LocalPlayer

function countryCodeToEmoji(countryCode) -- // using our function

	countryCode = countryCode:upper()

	local firstLetter = countryCode:sub(1, 1)
	local secondLetter = countryCode:sub(2, 2)

	local firstEmoji = utf8.char(0x1F1E6 + (firstLetter:byte() - 65))
	local secondEmoji = utf8.char(0x1F1E6 + (secondLetter:byte() - 65))

	return firstEmoji .. secondEmoji
	
end

local result, code = pcall(function()
	return LocalizationService:GetCountryRegionForPlayerAsync(Player)
end)

local countryEmoji = countryCodeToEmoji(code)

-- // do whatever with the emoji

Heres how I used it:

Example 1

image
Yes… I copied Pet Sim haha.

:heart: Thank you for reading!

(if this helps you feel free to like :happy1:)

13 Likes

Thanks a lot! It could come in handy for me at one point, and its really nice of you to make this.

2 Likes

This is really cool! I asked chatGPT to explain it a little more since I don’t really understand the utf8 library(might look into it sometime), and the way you did it was genius lol.

3 Likes

Thought it could help someone haha, didn’t take tooooooo long.

2 Likes

After looking at this I cut down the code a bit

print((string.gsub("us", ".", function(c)
    return utf8.char(0x1F1A5 + c:upper():byte())
end))) --> 🇺🇸
2 Likes

Awesome work! I only made it extended so people could change functionalities ect ect, but thats nice!

2 Likes

Hahah, no worries, just thought it could help someone make some sort of something :rofl:

2 Likes