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"
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)
Features
- Images, Decals and ImageButtons
- Emojis
- Country Name
- Both Server and Client Sided
- Support for types
local playerCountry: CountryService.Country = CountryService:GetPlayerCountry(player)
Example Place
Want to see it in action? I set up a copy unlocked place! CountryService - Example Place - Roblox
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
Please leave a star in the GitHub and or a heart on this post , it takes less than 10 seconds and it helps me a lot!