
Key RequiredUniversal

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local CoreGui = game:GetService("CoreGui")
local UPDATE_INTERVAL = 0.5
local floor = math.floor
-- pre-computed colors
local GREEN = Color3.fromRGB(0, 255, 0)
local YELLOW = Color3.fromRGB(255, 200, 0)
local RED = Color3.fromRGB(255, 60, 60)
local GRAY = Color3.fromRGB(180, 180, 180)
-- destroy old instance on re-execution
local old = CoreGui:FindFirstChild("PingDisplay")
if old then old:Destroy() end
local gui = Instance.new("ScreenGui")
gui.Name = "PingDisplay"
gui.ResetOnSpawn = false
gui.IgnoreGuiInset = true
gui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
gui.Parent = CoreGui
local label = Instance.new("TextLabel")
label.Name = "PingLabel"
label.BackgroundTransparency = 1
label.AnchorPoint = Vector2.new(1, 0)
label.Position = UDim2.new(1, -8, 0, 8)
label.Size = UDim2.fromOffset(140, 20)
label.Font = Enum.Font.Gotham
label.TextSize = 14
label.TextXAlignment = Enum.TextXAlignment.Right
label.TextYAlignment = Enum.TextYAlignment.Top
label.TextColor3 = GRAY
label.TextStrokeTransparency = 0
label.Text = "Ping: -- ms"
label.Parent = gui
local function colorForPing(ms)
if ms < 80 then
return GREEN
elseif ms < 160 then
return YELLOW
else
return RED
end
end
local lastMs
task.spawn(function()
while true do
local ping = LocalPlayer:GetNetworkPing()
if ping and ping == ping and ping < math.huge then
local ms = floor(ping * 1000)
-- only write when the displayed value actually changes
if ms ~= lastMs then
lastMs = ms
label.Text = "Ping: " .. ms .. " ms"
label.TextColor3 = colorForPing(ms)
end
else
if lastMs ~= nil then
lastMs = nil
label.Text = "Ping: --"
label.TextColor3 = GRAY
end
end
task.wait(UPDATE_INTERVAL)
end
end)No comments yet for this script.



