Skip to content

Instantly share code, notes, and snippets.

@nodomw
Created November 8, 2022 18:38
Show Gist options
  • Save nodomw/e7532db51ba7db4f552d83efd79a33fc to your computer and use it in GitHub Desktop.
Save nodomw/e7532db51ba7db4f552d83efd79a33fc to your computer and use it in GitHub Desktop.
Drawing.WaitForRenderer()
TextFont = DrawFont.Register(
game:HttpGet'https://github.com/bluescan/proggyfonts/raw/master/ProggyVector/ProggyVector%20Regular.ttf',
{ PixelSize = 32, UseStb = false, Scale = true, Bold = false }
)
local stats = game:GetService("Stats"):WaitForChild("Network"):WaitForChild("ServerStatsItem")
local camera = workspace.CurrentCamera
local RunService = game:GetService("RunService")
local GuiService = game:GetService("GuiService")
local TimeFunction = RunService:IsRunning() and time or os.clock
local LastIteration, Start
local FrameUpdateTable = {}
local FPSText = TextDynamic.new()
FPSText.Font = TextFont
FPSText.Size = 13
FPSText.YAlignment = YAlignment.Center
FPSText.XAlignment = XAlignment.Right
FPSText.Outlined = true
FPSText.OutlineOpacity = 0.8
FPSText.OutlineColor = Color3.fromRGB(0, 0, 0)
FPSText.OutlineThickness = 5
local PingText = TextDynamic.new()
PingText.Font = TextFont
PingText.Size = 13
PingText.Outlined = true
PingText.YAlignment = YAlignment.Center
PingText.XAlignment = XAlignment.Right
PingText.OutlineOpacity = 0.8
PingText.OutlineColor = Color3.fromRGB(0, 0, 0)
PingText.OutlineThickness = 5
local TimeoutText = TextDynamic.new(Point2D.new(.5, 0, .325, 0))
TimeoutText.Font = TextFont
TimeoutText.Size = 13
TimeoutText.Outlined = true
TimeoutText.YAlignment = YAlignment.Center
TimeoutText.XAlignment = XAlignment.Center
TimeoutText.Color = Color3.new(1, 1, 1)
TimeoutText.OutlineOpacity = 0.8
TimeoutText.OutlineColor = Color3.fromRGB(0, 0, 0)
TimeoutText.OutlineThickness = 5
TimeoutText.Visible = false
function FramerateUpd()
LastIteration = TimeFunction()
for Index = #FrameUpdateTable, 1, -1 do
FrameUpdateTable[Index + 1] = FrameUpdateTable[Index] >= LastIteration - 1 and FrameUpdateTable[Index] or nil
end
FrameUpdateTable[1] = LastIteration
local fps = math.floor(
TimeFunction() - Start >= 1 and #FrameUpdateTable or #FrameUpdateTable / (TimeFunction() - Start)
)
-- FPSText.Position = Point2D.new(camera.ViewportSize.X - FPSText.TextBounds.X, 5)
FPSText.Position = Point2D.new(1, -FPSText.TextBounds.X, 0, 5)
if fps <= 30 then
FPSText.Color = Color3.fromRGB(255, 0, 0)
elseif fps <= 60 then
FPSText.Color = Color3.fromRGB(255, 217, 0)
elseif fps <= 144 then
FPSText.Color = Color3.fromRGB(0, 255, 0)
else
FPSText.Color = Color3.fromRGB(255, 255, 255)
end
FPSText.Text = fps .. "fps"
end
function PingUpd()
-- PingText.Position = Point2D.new(camera.ViewportSize.X - PingText.TextBounds.X, 20)
PingText.Position = Point2D.new(1, -PingText.TextBounds.X, 0, 20)
local pingValue = stats:FindFirstChild("Data Ping")
local ping = nil
if pingValue then
ping = tonumber(pingValue:GetValueString():match("[^.]+"))
end
if ping then
if ping <= 60 then
PingText.Color = Color3.fromRGB(255, 255, 255)
elseif ping <= 100 then
PingText.Color = Color3.fromRGB(0, 255, 0)
elseif ping <= 300 then
PingText.Color = Color3.fromRGB(255, 217, 0)
else
PingText.Color = Color3.fromRGB(255, 0, 0)
end
PingText.Text = ping .. "ms"
end
end
-- function TimeoutUpd()
-- local lastKbps
-- local lastTime = tick()
-- local downTime = 0
-- local delta = tick() - lastTime
-- local new = Stats.DataReceiveKbps
-- if new == lastKbps then
-- if GuiService:GetErrorCode() == Enum.ConnectionError.OK then
-- downTime += delta
-- if downTime >= 1 then
-- TimeoutText.Text = "Server not responding... " .. string.format("%0.2f", downTime)
-- TimeoutText.Visible = true
-- else
-- TimeoutText.Visible = false
-- end
-- end
-- else
-- downTime = 0
-- TimeoutText.Visible = false
-- end
-- lastKbps = new
-- lastTime = tick()
-- end
Start = TimeFunction()
RunService:BindToRenderStep("FramerateUpd", 1, FramerateUpd)
RunService:BindToRenderStep("PingUpd", 1, PingUpd)
-- RunService:BindToRenderStep("TimeoutUpd", 1, TimeoutUpd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment