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)
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)
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?
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:
When a player donates to your game, save how much they donated to the ordered datastore by using their userid in the key
Iterate through the datastore pages object for the number one guy which should be the userid of the top player
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.