Is there a way to find the country of a player if he is not in the server?

Hi, i want to check the player country if a player is not in the server (i need it for a donation board, bc i want that there is the donator and the country where the donator is from ), i use LocalizationService, but if a player is not in the server it says me that argument 1 is missing or nil, maybe there is a way with PolicyService, but i don’t know how to get the country with it

	local Country = LocalizationService:GetCountryRegionForPlayerAsync(Player)

Ty for aswers : D

1 Like

You can’t do it outside your game, but I found a solution to your problem, I think. Heres what you are suppose to do. (I think)

local Player = game.Players.LocalPlayer

local Localizationservices = game:GetService("LocalizationService")

local result, code = pcall(function()

return Localizationservices:GetCountryRegionForPlayerAsync(Player)

end)

print(result and code)

Hope this helps

Ty for the answer… Adding a pcall is a very good idea, but the player must be in the server for get the country of him… So the solution would be do the country and then save it? Or maybe there is a nother solution?

I believe you could save it. I’m not sure if there’s is another solution.

As @amielcousineau stated, you’d need to save it. Since you said in your original post that you have a donation board already set up so I’m assuming you got an ordered datastore set up for tracking who donated how much. If not then you should ideally switch to it since it’s main purpose is for number value data storage. If you do then it should be really simple to get the top donors country by:

  1. When a player donates to your game, save how much they donated to the ordered datastore by using their userid in the key

  2. Using OrderedDataStore:GetSortedAsync() to get the top donors in your game, probably only the number 1 guy in this case.

  3. Iterate through the datastore pages object for the number one guy which should be the userid of the top player

  4. Convert that string key into a number and pass it through GetCountryRegionForPlayerAsync(Player)

P.S : The GetSortedAsync() api reference has sample code to give you an idea

EDIT: Actually discard step 4. I don’t think it’s possible to get the country for a player that’s offline because the GetCountryRegionForPlayerAsync() call requires a player that is in game, and there’s not really a way to get a player instance when they aren’t in game.

2 Likes

Ty for the answer, so basically the answer at the question: Is there a way to find the country of a player if he is not in the server? is No

1 Like