How would I go about getting in this image, the players country flag?
I don’t want how to do that in a playerlist, I just wanna know how to get the players flag so I can put it in my custom playerlist.
read this to get your information i guess
Its about how to get the players country, not its flag/region
If that script can get the country that’s all you need. You’ll have to fill in the rest yourself.
yeah but you can VERY easily match up flags with region by checking through a table with flag images
and seeing
if Country = v then
--get the image and stuff
end
ok, were do I put that code at? I have tried that code before didn’t seem to work properly for me
cant you just put it in a server script or something? i didnt make the solution to the post i dont know
just an idea.
I lost where I got it from but I sourced most of it from the dev forum.
LOCALSCRIPT:
local LocalizationService = game:GetService("LocalizationService")
local player = game.Players.LocalPlayer
local flags = { -- what ever the region code is
["ca"] = "rbxassetid://12345",
["us"] = "rbxassetid://12345",
["mx"] = "rbxassetid://12345",
}
local result, code = pcall(function()
return LocalizationService:GetCountryRegionForPlayerAsync(player)
end)
if result then
print("Hello, "..code..flags[string.lower(code)])
else
print("GetCountryRegionForPlayerAsync failed: " .. code)
end
I got it … give me a sec to put it together.
flag.rbxl (58.5 KB)
You’ll have to do the rest …
This will give you the country and a flag graphic.
Run this and check your output.
Jack lead me to it.
local LocalizationService = game:GetService("LocalizationService")
local HttpService = game:GetService("HttpService")
local countryFlagJSON = "http://cdn.jsdelivr.net/npm/country-flag-emoji-json@2.0.0/dist/index.json"
local function countryCodeToEmoji(countryCode: string)
local jsonTable = HttpService:GetAsync(countryFlagJSON)
local countryTable = HttpService:JSONDecode(jsonTable)
local emoji = ""
for _, country in ipairs(countryTable) do
if country.code == countryCode then
emoji = country.code
end
end
return emoji
end
-- pretend that 'player' exists and it is a Player object
local countryCode = LocalizationService:GetCountryRegionForPlayerAsync(player)
-- if player is in the United States, this will return "US"
print(countryCode) --> US
print(countryCodeToEmoji(countryCode)) --> 🇺🇸
This code returns nil on line 15
Tried this, its only for USA not other countries
I tried this, doesn’t work at all neither does it print.
Because you’re from America. If you were in some other place it would return that.
I am from saudi arabia, riyadh not from america.
Well then …
Anyway there is a nice module in that script for the flag graphics.
cool, although i need to get the country for that
I should post where I found that … someone did a lot of work. Should get the credit for it.
flag module
Please if anyone has a solution, tell me I need to know how to get the players country and how to get the country image id from the module 2112jay sent.
This isn’t working?
local function getCountry()
local HttpService = game:GetService("HttpService")
local response = HttpService:GetAsync("https://ipinfo.io/json")
local data = HttpService:JSONDecode(response)
return data.country
end
The accuracy of this method depends on the player’s IP address and the data provided by the “ipinfo.io” service. It may not always accurately reflect the player’s actual physical location or country, as IP addresses can be associated with various locations, including VPN servers and proxies.