Roblox FPS

-- messy code but it works ig
local runservice = game:GetService("RunService")

local delta_times = {}

local render_start_old = os.clock()
local after_1s = render_start_old + 1

runservice.RenderStepped:Connect(function()
	local render_start = os.clock()
	table.insert(delta_times, os.clock() - render_start_old)
	render_start_old = render_start
	
	if #delta_times > 0 then
		if render_start > after_1s then
			table.remove(delta_times, 1)
		end
		
		local avg_frame_time = 0
		for _, value in pairs(delta_times) do
			avg_frame_time += value
		end
		
		avg_frame_time /= #delta_times
		
		local fps = nil
		if avg_frame_time > 0 then
			fps = string.format("%.0f", 1 / avg_frame_time)
		end
		
		if fps then
			-- set something to "fps" here
		end
	end
end)
cyn