CountryService (Country data Module)

Documentation | Source

:nerd_face: Introduction

CountryService is a small Library that allows you to obtain the information about a players country. You can get their Country name, country emoji and even country flag! The LocalizationService only returns the country code, nothing else, no flag, no country name, no nothing else hence why I decided to do this!

LocalizationService:GetCountryRegionForPlayerAsync(player) -- Only returns "US"

:hammer: Code Example

Here I will be showing some examples on how to use the CountryService.

local CountryService = require(ReplicatedStorage.CountryService) -- Get the library
local country = CountryService:GetMyCountry() -- Get the country of the player (only works in local scripts)
local country = CountryService:GetPlayerCountry(player) -- Get the country of the player you insert (works on local and server scripts)

print(country) -- {emoji = "flag", decal ="rbxassetid://id", name = "countryName"}

CountryService works on both the Client and Server side. Here are two examples, 1 for each side.

Client Example (LocalScript)

local  ReplicatedStorage = game:GetService("ReplicatedStorage")
local  Players = game:GetService("Players")

local  CountryService = require(ReplicatedStorage.CountryService)

local  localPlayer: Player = Players.LocalPlayer
local  playerGui: PlayerGui = localPlayer.PlayerGui

--Gets the country of the player
local  country = CountryService:GetMyCountry()

--Set the UI
local  screenGui: ScreenGui = playerGui:WaitForChild("Country") :: ScreenGui
local  container: Frame = screenGui:WaitForChild("Container") :: Frame

local  countryFlag: ImageLabel = container:WaitForChild("CountryFlag") :: ImageLabel
local  countryInfo: TextLabel = container:WaitForChild("CountryInfo") :: TextLabel

countryFlag.Image = country.decal -- Uses the country flag

countryInfo.Text = `Hi! Welcome from {country.name}  {country.emoji}` -- Uses the country name and emoji

Server Example (Script)

local  ReplicatedStorage = game:GetService("ReplicatedStorage")
local  Players = game:GetService("Players")

local  CountryService = require(ReplicatedStorage.CountryService)
--Set country tags
Players.PlayerAdded:Connect(function(player: Player)
	player.CharacterAdded:Connect(function(character: Model)
		local  playerCountry = CountryService:GetPlayerCountry(player)
		local  label: string = `{playerCountry.emoji}  {player.Name} | {playerCountry.name}`
		local  newGui: BillboardGui = template:Clone()
		local  countryInfo: TextLabel = newGui:WaitForChild("CountryInfo") :: TextLabel

		countryInfo.Text = label

		newGui.Parent = character.PrimaryPart
	end)
end)

:cookie:Features

  • Images, Decals and ImageButtons
  • Emojis
  • Country Name
  • Both Server and Client Sided
  • Support for types
local  playerCountry: CountryService.Country = CountryService:GetPlayerCountry(player)

:house:Example Place

Want to see it in action? I set up a copy unlocked place! CountryService - Example Place - Roblox

:file_folder:Download

There’s 3 ways you can get this library so feel free to go with which ever you’re the most comfortable.

Roblox Studio Model: CountryService - V.1.0 - Roblox

Wally: Wally

GitHub Release: GitHub - prooheckcp/CountryService: CountryService is a small Library that allows you to obtain the information about a players country. You can get their Country name, country emoji and even country flag!

Please leave a star :star: in the GitHub and or a heart on this post :heart:, it takes less than 10 seconds and it helps me a lot!

44 Likes

1 Like

Thanks for pointing this out, I will fix the Brazil emoji and do a quick check over all the emojis to make sure there aren’t more mistakes

2 Likes

Small Update to CountryService. I updated the model, Wally, and GitHub with it.

Added Functions

  • GetMyCountryCode()
  • GetPlayerCountryCode(player: Player)

Fixed Countries Emojis

  • Brazil
  • Uzbekistan
1 Like

What country code you meant? the ISO Code? like AE = United Arab Emirates?

Yes, Roblox returns the Alpha-2 code (a type of ISO code) via the LocalizationService. CountryService uses that code and returns information about the country

1 Like

Hello I am using this script for a custom leaderboard and it appears GetPlayerFromCode() isnt working even if you call a object which is a player type in a client script despite you saying that that function would work in a client script.

Here is the errors I got:

  13:33:16.360  ReplicatedStorage.CountryService:110: attempt to index nil with Instance  -  Client - CountryService:110
  13:33:16.360  Stack Begin  -  Studio
  13:33:16.360  Script 'ReplicatedStorage.CountryService', Line 110 - function GetPlayerCountryCode  -  Studio - CountryService:110
  13:33:16.360  Script 'Players.PatrickWheels.PlayerScripts.LeaderboardEvents', Line 41 - function buildEntry  -  Studio - LeaderboardEvents:41
  13:33:16.361  Script 'Players.PatrickWheels.PlayerScripts.LeaderboardEvents', Line 86 - function InitializeLeaderboard  -  Studio - LeaderboardEvents:86
  13:33:16.361  Script 'Players.PatrickWheels.PlayerScripts.LeaderboardEvents', Line 190  -  Studio - LeaderboardEvents:190

CountryService- V.0.2

Major polishing of the library

:wrench:Changes

  • Support getting the player’s country from the client
  • Allowing both capitalized and lowercased indexing of countries’ information
  • Massive cleaning and performance boost on the code
  • Proper documentation
  • New ReadMe file
  • Adding .Icon property to countries’ data for easier access
1 Like

Sorry for the delay, just did a big update to the library which will resolve this as well

1 Like