local HttpService = game:GetService("HttpService") local Players = game:GetService("Players") local UserInputService = game:GetService("UserInputService") local function getPlayerGeolocation(player) local success, result = pcall(function() -- Use a service that returns the geolocation data based on IP. local url = "http://ip-api.com/json" -- Returns JSON with IP and location data local response = HttpService:RequestAsync({ Url = url, Method = "GET" }) return response.Body end) if success then local decoded = HttpService:JSONDecode(result) if decoded and decoded.status == "success" then return { city = decoded.city, region = decoded.regionName, country = decoded.country, } else warn("Failed to retrieve geolocation data, or service returned an error for " .. player.Name .. ": " .. result) return nil end else warn("Failed to retrieve geolocation data for " .. player.Name .. ": " .. result) return nil end end local function createLocationGUI(player, locationData) -- Create the GUI on the Player's PlayerGui local playerGui = player:WaitForChild("PlayerGui") local screenGui = Instance.new("ScreenGui") screenGui.Name = "LocationGui" screenGui.Parent = playerGui local frame = Instance.new("Frame") frame.Size = UDim2.new(0.4, 0, 0.3, 0) frame.Position = UDim2.new(0.3, 0, 0.4, 0) frame.AnchorPoint = Vector2.new(0.5, 0.5) frame.BackgroundColor3 = Color3.new(0.8, 0.8, 0.8) frame.BorderColor3 = Color3.new(0, 0, 0) frame.BorderSizePixel = 2 frame.Parent = screenGui local titleLabel = Instance.new("TextLabel") titleLabel.Size = UDim2.new(1, 0, 0.2, 0) titleLabel.Position = UDim2.new(0, 0, 0, 0) titleLabel.Font = Enum.Font.ArialBold titleLabel.Text = "Your Location:" titleLabel.TextScaled = true titleLabel.Parent = frame local locationLabel = Instance.new("TextLabel") locationLabel.Size = UDim2.new(1, 0, 0.8, 0) locationLabel.Position = UDim2.new(0, 0, 0.2, 0) locationLabel.Font = Enum.Font.Code locationLabel.Text = (locationData and "City: " .. locationData.city .. "\n" .. "Region: " .. locationData.region .. "\n" .. "Country: " .. locationData.country) or "Failed to get location" locationLabel.TextScaled = true locationLabel.Parent = frame frame.Draggable = true local function onInput(input, gameProcessedEvent) if gameProcessedEvent then return end if input.KeyCode == Enum.KeyCode.Escape then screenGui:Destroy() end end UserInputService.InputBegan:Connect(onInput) return screenGui end game.Players.PlayerAdded:Connect(function(player) local locationData = getPlayerGeolocation(player) if locationData then createLocationGUI(player, locationData) else createLocationGUI(player, nil) -- Pass nil to show "Failed to get location" end end)