Player Country Flag And Minutes In Leaderstats! (SAVES!)

Hello! i made this leaderstats script cause i think it’s pretty useful and i couldn’t find it in here, feel free to share your suggestions on it!

Here’s how it looks like:
image

Code:

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("TimeStats")

function getFlagEmoji(player)
	-- Dictionary of regional indicators indexable by the regular letter
	local regionalIndicators = {
		a = "🇦",
		b = "🇧",
		c = "🇨",
		d = "🇩",
		e = "🇪",
		f = "🇫",
		g = "🇬",
		h = "🇭",
		i = "🇮",    
		j = "🇯",
		k = "🇰",
		l = "🇱",
		m = "🇲",
		n = "🇳",
		o = "🇴",
		p = "🇵",
		q = "🇶",
		r = "🇷",
		s = "🇸",
		t = "🇹",
		u = "🇺",
		v = "🇻",
		w = "🇼",
		x = "🇽",
		y = "🇾",
		z = "🇿",
	}

	-- Get region ID to translate into reg-ind characters
	local regionID = string.lower(game:GetService("LocalizationService"):GetCountryRegionForPlayerAsync(player))
	local l1 = string.sub(regionID, 1, 1) -- Get the first letter
	local l2 = string.sub(regionID, 2, 2) -- Get the second letter
	return regionalIndicators[l1] .. regionalIndicators[l2] -- Index the regional indicators for each letter, concatenating the result into a single string that is equivalent to the flag code
end

game.Players.PlayerAdded:Connect(function(Player)
	local Leaderstats = Instance.new("Folder")
	Leaderstats.Name = "leaderstats"
	Leaderstats.Parent = Player

	local Minutes = Instance.new("IntValue")
	Minutes.Name = "Minutes"
	Minutes.Value = 0
	Minutes.Parent = Leaderstats

	local Data = DataStore:GetAsync(Player.UserId)
	if Data then
		Minutes.Value = Data
	end

	coroutine.resume(coroutine.create(function()
		while true do
			wait(60)
			Minutes.Value = Minutes.Value + 1
		end
	end))

	local Status = Instance.new("StringValue")
	Status.Name = "Language"
	Status.Value = getFlagEmoji(Player)
	Status.Parent = Leaderstats
end)

game.Players.PlayerRemoving:Connect(function(Player)
	DataStore:SetAsync(Player.UserId, Player.leaderstats.Minutes.Value)
end)

FILE (ServerScriptService):
Flag And Minute Leaderboard (Saves).lua (1.8 KB)

9 Likes

Cool, but can you change “Language” to “Country”?

Language is a system of communication

Country is a land

and you’re putting a country flag, You would need to know what is different from language and country

image

also I recommend using task.spawn instead of resuming and creating a coroutine at the same time

image

1 Like

Isn’t that what LocalizationService already does?

1 Like

Read the code again, he is using LocalizationService, also it doesn’t return something like 🇦🇪, something like “AE”

Ah, its weirdly cut off for me.

just change the Name value, to country

Here, Let me help you

image

Not everyone is going to do so then they will get confused because the country and the language are different things