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:
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)