How can i see the host of the player that joined the game first

Hello first of all welcome to my thread i need help with localization service to detect the host of the first player that joined and prevent it getting other hosts of the people that joined the game later

So you want to check who joined the server first or what?

What do you mean by “Host of the player”?

local players = game:GetService"Players"

local playersArray = table.create(players.MaxPlayers)

players.PlayerAdded:Connect(function(player)
	table.insert(playersArray, player)
end)

players.PlayerRemoving:Connect(function(player)
	table.remove(playersArray, table.find(playersArray, player))
end)

game:BindToClose(function()
	table.clear(playersArray)
end)

With this, the first item/element of the array named “playersArray” will always be the server’s oldest player instance.

Sorry for the very late response but what i mean by that is host of the player which means its player’s host location like if i am turkey it will display turkey it is the player’s country location sorry for bad explaining my english is bad

Also yes i need to check the first player then stop checking the other players that joins late in the game so i can get the first host of the player and display it as a gui bottom corner to notify host of the server

AFAIK clients don’t host instances, servers are separate entities that spawn up when there’s at minimum one client in the current instance. You should check the server’s information if you’re looking for a host region rather than relying on the first joining client for this, as the information you get from the first client could be inaccurate to the server’s actual regional data.

I suggest ip-api for this.

local HttpService = game:GetService("HttpService")

-- Make a GET request to ip-api
local success, response = pcall(function ()
    return HttpService:RequestAsync({
        ["Url"] = "http://ip-api.com/json/",
        ["Method"] = "GET"
    })
end)

-- Print contents of HTTP response table (can print directly if in Studio)
if success and response and typeof(response) == "table" then
    for key, value in pairs(response) do
        print(key, value)
    end

    -- Used to separate print results if not running in Studio
    warn("---")

    -- Assuming Body is a JSON object, decode for a Luau table
    local serverGeolocationInfo = HttpService:JSONDecode(response.Body)
    for key, value in pairs(serverGeolocationInfo) do
        print(key, value)
    end
end

That’s assuming what you’re trying to achieve is a server geolocation display Gui. I can’t really grasp your exact use case but since you’re concerned with the “host” of the “first player”, I’d assume this is akin to what you’re looking for. You can use the server’s geolocation information instead.

3 Likes

You can Put a string value inside the script and a boolean value as well.

When the first player joins use PlayerAdded event and put the player’s name inside the string value and make the boolean value set to false.

Here is a demonstration of what I’m saying:

local Players = game:GetService("Players") 
local first = false
local PlayerName

Players.PlayerAdded:Connect(function(player)

if first == false then 
first = true
PlayerName = player.Name
end

end)

This script however works only once and will stop working if the first player joins. I hope you don’t need it more then once :joy:

1 Like

That worked but i need city and the country of it i dont need all of the information

nvm i figured out

but a problem tho it does “OK” when i try to make field appear as host

nvm i figured that out aswell ty